[pmwiki-users] Improving a certain recipe script

H. Fox haganfox at users.sourceforge.net
Thu Mar 30 01:26:50 CST 2006


On 3/29/06, Patrick R. Michaud <pmichaud at pobox.com> wrote:
> On Wed, Mar 29, 2006 at 08:40:45PM -0700, H. Fox wrote:
> > On 3/29/06, H. Fox <haganfox at users.sourceforge.net> wrote:
> > > How would I test for the following in a recipe script:
> > >
> > > $SomeNumber = NN;
> > > if (a line in wikitext starts with a space and has more than
> > > $SomeNumber characters) { # Do something. }
> >
> > Not a line in wikitext, a line in posted wikitext.  I think it will be
> > something like
> >
> > if preg_match("!^ <something>$!", @$_POST['text']) # Do something.
> >
> > where <something> is Perl regular-expressionese for "more than
> > $SomeNumber characters".
>
> Assuming you don't need to match newlines:
>
>     preg_match("!^ .{$SomeNumber,}!", ...)
>
> If you need to count newlines in the some number of characters,
> add an 's' modifier:
>
>     preg_match("!^ .{$SomeNumber,}!s", ...)

It doesn't like the comma inside the curlies.

If I put this wikitext line somewhere in the page

   <space>1234567889

(so the 9 is "10 characters in") none of these matches:

   $SomeNumber = 4;
   if (preg_match("!^ .{$SomeNumber}!", $_POST['text'])) { ... }
   if (preg_match("!^ .{$SomeNumber},!", $_POST['text'])) { ... }
   if (preg_match("!^ .{$SomeNumber}!s", $_POST['text'])) { ... }
   if (preg_match("!^ .{$SomeNumber}!,s", $_POST['text'])) { ... }

Hagan




More information about the pmwiki-users mailing list