Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Regexp: Match anything except a certain word

by fraktalisman (Hermit)
on Apr 21, 2006 at 13:19 UTC ( [id://544953]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: Regexp: Match anything except a certain word
in thread Regexp: Match anything except a certain word

Thanks! This looks good, although it does not check for http and so it also put the target to local links, but I should be able to put the pieces together now.

Replies are listed 'Best First'.
Re^3: Regexp: Match anything except a certain word
by ikegami (Patriarch) on Apr 21, 2006 at 13:26 UTC
    Oops, I read the problem too fast. Fix:
    $test =~ s{ ( <a\s (?:(?!target=|>).)* href="http:// (?:(?!target=|>).)* ) (?=>) }{$1 target="_blank"}xsgi;

    Alternatively, the following *might* be faster, especially considering href is usually the first attribute:

    $test =~ s{ ( <a\s (?:(?!href=|target=|>).)* href="http:// (?:(?!target=|>).)* ) (?=>) }{$1 target="_blank"}xsgi;

    Tested.

    Update: Collapsed (?!..re1..)(?!..re2..) into (?!..re1..|..re2..)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://544953]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.