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:
( # <1>
([a-zA-Z:]+) # <2/>
\s* = \s*
(/\s*)? # <3/>
(?:[^<>]* | (?1))*
) # </1>
And this time, everything matches (or matches not) correctly:
<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)
<card id="mail" title="C: WAP POP3">
<setvar name="host" value="mail.some-domain"/>
<input type="text" format="*m" name="host" value="$(host)"
<input type="text" format="*m" name="user"/>
<input type="password" format="*m" name="pass"/>
This single regex can actually test XML well-formedness :)
(Doesn't take <?xml?> and <!DOCTYPE> etc, though)
Those with an *
didn't work with the previous patch, but do now.
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.