Regexp exception

I have a regular expression for changing emoticons to images. Here

(?:(?![0]:\)|:\)\)|:-\)\)))(:\)|:-\)) 

It's not about changing 0 :) and :)) and :-)) when changing :) and :-) It works great with :)) and :-)) but for some reason it still suffices :) at 0 :)

Where is my mistake?

+6
regex exception
source share
1 answer

So, you want to compare :) and :-) , but they should not be preceded by 0 or should it follow yet ) ? Then this is the template:

 (?<!0):-?\)(?!\)) 

Mainly

 (?<!0) : negative lookbehind; must not be preceded by 0 :-?\) : smiley with optional nose (?!\)) : negative lookforward; must not be followed by ) 

Example:

 $ echo ':) :-) ok 0:) :)) :-)) 0:-)) 0:-) : )' | \ > perl -lne'print $1 while /(?<!0)(:-?\))(?!\))/g' :) :-) 
+5
source share

All Articles