Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

RE: Answer: Regex anchor speed ?: Is /^.*X/ faster than /X/ ?

by Dominus (Parson)
on Nov 12, 2000 at 22:25 UTC ( [id://41205]=note: print w/replies, xml ) Need Help??


in reply to Re: Regex anchor speed ?: Is /^.*X/ faster than /X/ ?
in thread Regex anchor speed ?: Is /^.*X/ faster than /X/ ?

Ovid said:
> The /^.*\@/ is forced to match to
> the end of the string (or to a newline) and then backtrack to the @ symbol.
But 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.

Isn't that interesting?

The nongreedy .*? version is optimized similarly, so I would be surprised if it performed any differently in this example.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://41205]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 19:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found