[pmwiki-users] Improving a certain recipe script

Patrick R. Michaud pmichaud at pobox.com
Wed Mar 29 23:09:54 CST 2006


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", ...)

Pm




More information about the pmwiki-users mailing list