Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Regexp: Match anything except a certain word

by SamCG (Hermit)
on Apr 21, 2006 at 17:07 UTC ( #544948=note: print w/ replies, xml ) Need Help??


in reply to Regexp: Match anything except a certain word

Sounds like you want a negative look-ahead? Aren't those expressed something like $test=~/<a.+?(?!target).+?>/;?

Sort of guessing at the form, but I think that's what you're after...

update: this has a problem because of the .+.



-----------------
s''limp';@p=split '!','n!h!p!';s,m,s,;$s=y;$c=slice @p1;so brutally;d;$n=reverse;$c=$s**$#p;print(''.$c^chop($n))while($c/=$#p)>=1;


Comment on Re: Regexp: Match anything except a certain word
Select or Download Code
Re^2: Regexp: Match anything except a certain word
by ikegami (Pope) on Apr 21, 2006 at 17:15 UTC

    That's not how you use the negative lookahead. It won't work. For example,

    '<a href="..." target="...">' =~ / <a # Matches '<a'. .+? # Matches ' '. (?!target) # Matches. (/\Gtarget/ doesn't match.) .+? # Matches 'href="..." target="..."'. > # Matches '>'. /isx;
    and
    '<a target="..." href="...">' =~ / <a # Matches '<a'. .+? # Matches ' t'. (?!target) # Matches. (/\Gtarget/ doesn't match.) .+? # Matches 'arget="..." href="..."'. > # Matches '>'. /isx;

    The common use of a negative lookahead is

    /(?:(?!$re).)*/

    See my earlier post for the fix.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2014-10-22 23:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (122 votes), past polls