[pmwiki-users] pattern matching:

The Editor editor at fast.st
Sun Dec 3 12:38:13 CST 2006


On 12/3/06, J. Meijer <commentgg at hotmail.com> wrote:
>
> On 12/2/06, The Editor <editor at fast.st> wrote:
> I'm working on a "special" project and trying to get this pattern
> match to work and it almost works, but I seem to be having some
> problems with :, -, and . in the [ ].
>
> preg_replace('|\{@ ([\-\.A-Za-z0-9:_]+)\}|e', "Function($1)", $text);
>
> I'm trying to get this to match expressions like the following:
>
> {@ TEXT:Group.Name-36_End}
>
> Any help would be appreciated.
>
> Cheers,
> Caveman
>
> ----------
>
>
> Hi Caveman,
>
> I'm not at my desk, so I'm unable to test the following.
>
> The problem with your regex seems to be with delimiters: I don't think the pipe | symbol is allowed to be used. It's used within regexes. Furthermore, you don't need to escape anything but the delimiters inside a regex. That includes the charset ] end-delimiter. You did place the '-' at the start so it doesn't get interpreted as a a-z range.
>
> Your regex becomes simpler:
>
>  preg_replace('!\{@ ([-.A-Za-z0-9:_]+)\}!e', "Function($1)", $text);
>
> Hopefully this'll get you going again.
>
> ps Do you really want such a free form regex?? You'd normally want to decompose into elements.. and so strictly match each element.



Thanks so much jm,

But I'm still having troubles with some of the things.  Here's the
best I've been able to get so far, but I can't seem to get past it...

'!\{@ ([_A-Za-z0-9]+)\}!e'

1) Whenever I put - into the [], whether it's escaped or not, $1 goes
to 0 instead of the substring it's supposed to be.  Bad.

2) Whenever I put ^ into the [] (not at beginning), whether it's
escaped or not, $1 goes to null instead of the substring it's supposed
to be.  More bad.

3) Whenever I put : into the [], whether it's escaped or not, I get
the white screen of death (php error--still getting no error messags).
 Worse still.

4) Whenever I put . into the [] whether it's escaped or not, $1 shows
up with everything but the . in the output.  A little bad.

The only thing I can seem to get to work is the _.  I've been scouring
the web, trying to find tutorials and help, I'm learning a lot but
none of the tutorials explain this kind of behavior.  Am I missing
something?

Cheers,
Caveman




More information about the pmwiki-users mailing list