in reply to Alternative matches

Who said it's bad?

(If you're constructing the regexp programmatically, take care to quotemeta the parts.)

Replies are listed 'Best First'.
Re^2: Alternative matches
by kiat (Vicar) on Oct 06, 2004 at 09:22 UTC
    Hm...I had the impression it was something to be avoided because the long list of alternatives could slow things down...
      There are probably more and less efficient possible orderings of all the elements in your set, and very probably you can transform the regexp into something with shared prefixes and stuff, but to do that correctly you also need to know/make assumptions about the distribution of your input. For general purpose programming and in most cases, just assembling something like what's in your original post is fine.

      Of course, if you do need to match many timesm or if the alternate lists grow huge, you will need to optimize things.

        Thanks, gaal! I get the idea now :)
      Last time I checked, the list was a _lot_ faster than searching every item alone.
      Boris