Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Recursive Regex: Update

by Juerd (Abbot)
on Apr 20, 2002 at 13:03 UTC ( [id://160775]=note: print w/replies, xml ) Need Help??


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:

% ^ \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
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) <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)&amp;user=$(user:e)&amp;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)
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.

Replies are listed 'Best First'.
Re: Re: Recursive Regex: Update
by robin (Chaplain) on Apr 20, 2002 at 17:04 UTC
    If it were released as a module, it would be very nice.
    Well, writing a PCRE module with a procedural or object-oriented interface would be reasonably easy, if that's what you mean. Getting slightly more ambitious, if perl's regex engine were made properly pluggable, you could write a pragma to switch in the PCRE implementation.
    use PCRE; print "Well formed!\n" if /$Juerds_regex/;
    Out of interest, why wouldn't you like it replacing Perl's built-in engine? (supposing the UTF8 support were properly finished)

      Out of interest, why wouldn't you like it replacing Perl's built-in engine?

      As far as I know (although I haven't benchmarked), Perl's regex engine is faster. If it's not, PCRE may as well replace Perl's own regex engine, when UTF8 is fixed :) Then we'd have Perl with a Regex Engine that is Perl Compatible, which sounds reasonable...

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.
      

        Perl's regex engine is faster.
        Interesting: several people have said that. If anyone knows of any actual benchmarks, please let me know. Otherwise I'll try and do some of my own.
      if perl's regex engine were made properly pluggable

      Thats a great idea. Ive wanted to be able to use a DFA based engine under certain situations...

      Yves / DeMerphq
      ---
      Writing a good benchmark isnt as easy as it might look.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://160775]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-03-29 01:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found