in reply to Regex anchor speed ?: Is /^.*X/ faster than /X/ ?
Fastolfe is correct that a straight match will be faster. The /^.*\@/ is forced to match to the end of the string (or to a newline) and then backtrack to the @ symbol. This is extra overhead and will slow it down.
If you use minimal matching with /^.*?\@/, the regex matches every character (except for newline and end-of-string) and then looks ahead for the @ symbol. Again, you have extra overhead.
A simple scan for the @ symbol (/\@/) just looks for the @ symbol and returns true if found. That is the fastest way to scan for the character. See Death to Dot Star! if you wish to understand more about the dot metacharacters in regexes.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Answer: Regex anchor speed ?: Is /^.*X/ faster than /X/ ?
by Dominus (Parson) on Nov 12, 2000 at 22:25 UTC |