Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to Re: Re: Re: look-behind regex by Anonymous Monk
in thread look-behind regex by zejames

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found