Or instead of handcrafting it, use something like Regex::PreSuf, which groups substrings by longest prefixes (among other things).
If you are using a static set of alternations, I would recommend caching this somehow, though, it is rather expensive time-wise. Additionally, it isn't guaranteed to be faster, so benchmark with reasonable data. (see Re^4: removing stop words for example with benchmark.)
In reply to Re^2: pattern matching with large regex
by fishbot_v2
in thread pattern matching with large regex
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |