in reply to Recursive Regex: Update
All the known bugs have been fixed, and both the regexes that Juerd posted last time now seem to work.
They indeed do. Actually, there is only one, the second one doesn't use a conditional but is the same regex. Here is the regex again:
And this time, everything matches (or matches not) correctly:% ^ \s* ( # <1> < \s* ([a-zA-Z:]+) # <2/> (?: \s*[a-zA-Z:]* \s* = \s* (?:'[^']*'|"[^"]*") )* \s* (/\s*)? # <3/> > (?:[^<>]* | (?1))* (?(3)| <\s*/\s*\2\s*> ) ) # </1> \s* $ %x
Those with an * didn't work with the previous patch, but do now.<foo><bar></bar></foo> # Match <foo><bar></foo></bar> # No match <foo><bar/></foo> # Match * <foo><bar></foo> # No match <foo bar=baz/> # No match <foo bar="baz"> # No match <foo bar="baz"/> # Match < fooo / > # Match <foo/>foo # No match foo<foo/> # No match <foo>foo</foo> # Match <foo><bar/>foo</foo> # Match * <a><b><c></c></b></a> # Match * This one matches as well * (wow) <wml> <card id="mail" title="C: WAP POP3"> <onevent type="onenterforward"> <refresh> <setvar name="host" value="mail.some-domain"/> </refresh> </onevent> <p> Host: <input type="text" format="*m" name="host" value="$(host)" +/> <br/> User: <input type="text" format="*m" name="user"/> <br/> Pass: <input type="password" format="*m" name="pass"/> <br/> <a href="pop3.cgi?host=$(host:e)&user=$(user:e)&pa +ss=$(pass:e)"> Login </a> </p> </card> </wml> This single regex can actually test XML well-formedness :) (Doesn't take <?xml?> and <!DOCTYPE> etc, though)
On a slight tangent, is anyone else interested in the idea of (as an experiment) hacking perl to use the PCRE library in place of its built-in engine? I don't think it would be all that hard.
If it were released as a module, it would be very nice. Maybe it's even possible to create pcre_s/// and pcre_m//? If not, a normal functional interface or perhaps even object oriented interface to the PCRE library would be great. I wouldn't like it replacing Perl's built-in engine.
- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Recursive Regex: Update
by robin (Chaplain) on Apr 20, 2002 at 17:04 UTC | |
by Juerd (Abbot) on Apr 20, 2002 at 17:31 UTC | |
by robin (Chaplain) on Apr 21, 2002 at 14:35 UTC | |
by demerphq (Chancellor) on Apr 22, 2002 at 13:25 UTC |