Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: alternation in regexes: to use or to avoid?

by balker (Novice)
on Dec 10, 2012 at 18:42 UTC ( [id://1008148]=note: print w/replies, xml ) Need Help??


in reply to Re: alternation in regexes: to use or to avoid?
in thread alternation in regexes: to use or to avoid?

But that doesn't leave room for the various match-words to have different "\w+"'s - e.g. /\bFOO:\s*bar(\d+)/ or /\bBAZ:\s*(\w+)/

I guess I'm wondering why the trie-optimization isn't used for fixed string prefixes as well (as I'd assumed before I wrote the code).

  • Comment on Re^2: alternation in regexes: to use or to avoid?

Replies are listed 'Best First'.
Re^3: alternation in regexes: to use or to avoid?
by dave_the_m (Monsignor) on Dec 10, 2012 at 19:40 UTC
    Actually I stand corrected: the fixed string prefixes are collected together into a trie where there are (possibly differing) wildcard suffixes; the killer is the individual captures, which disables the trie optimisation.

    So, alternation is the fastest, as long as you put any captures outside the alt.

    Dave.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-23 18:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found