> The /^.*\@/ is forced to match toBut that is not exactly true. In general, Perl does behave that way. But in some cases, such as this one, there is an optimization: Perl sees that the string can't match unless it contains a @ character, so it looks for the @ first, and works outwards from there. In particular, it does not let .* match all the way to the end of the string and then backtrack it; it gets the right length for .* on the first try.
> the end of the string (or to a newline) and then backtrack to the @ symbol.
Isn't that interesting?
The nongreedy .*? version is optimized similarly, so I would be surprised if it performed any differently in this example.
In reply to RE: Answer: Regex anchor speed ?: Is /^.*X/ faster than /X/ ?
by Dominus
in thread Regex anchor speed ?: Is /^.*X/ faster than /X/ ?
by cshirky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |