in reply to How do I optimize a regular expression?
(?:thing){0} seems to be a poor man's comment. I'd use an ordinary #...\n comment instead, or (?#...) comments.
Second thing: split on whitespaces as far as possible, and then check the individual fields with anchored regexes
You can also use (?>...) non-backtracking groups for things that don't have to backtrack. That will make regexes fail faster if they can't match.
If you have the choice, use perl 5.10 or newer, it has a an awesome optimization for alternatives of literals.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do I optimize a regular expression?
by kyle (Abbot) on Dec 07, 2009 at 16:50 UTC | |
by moritz (Cardinal) on Dec 07, 2009 at 17:02 UTC |