Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Re: look-behind regex

by japhy (Canon)
on Jul 24, 2002 at 12:55 UTC ( [id://184798]=note: print w/replies, xml ) Need Help??


in reply to Re: look-behind regex
in thread look-behind regex

The problem I have with /(?:(?!foo).)*/ is its slowness. Update: I'm wrong. Apparently, this method is usually the fastest.

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: Re: look-behind regex
by Anonymous Monk on Jul 25, 2002 at 02:20 UTC
    In this particular case there's possibly a faster method though:

    s/^(?!(?>.*?toto.*?foo))(.*?)foo/${1}bar/s;

    If toto or foo can be found in the near beginning, Abigail's pattern is a winner. This is, I guess, due to the overhead of the (?>) assertion. But the farther away toto or foo is the worse it gets for the step-by-step method (/(?:(?!foo).)*/), and the (?>) pattern gets faster. (This isn't just a theoretical win. Even though the overhead due to (?>), that pattern might very well win in a real-life situation.)

    But if I shall look at the big picture for a while though; in this case I find it hard to believe that any pattern can beat the plain and simple

    s/foo/bar/ unless /toto.*?foo/s;

    Even silly constructions like

    s/foo(?(?{index($`, 'toto') != -1})(?!))/bar/;

    is faster than the more generic solutions.

    Cheers,
    -Anomo

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-23 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found