I have regexp to change smileys to images. Here it is
(?:(?![0]:\)|:\)\)|:-\)\)))(:\)|:-\))
The point is not to change 0:) and :)) and :-)) while changing :) and :-) It works pretty well with :)) and :-)) but somehow still grabs :) in 0:)
Where's my mistake?
So you want to match :)
and :-)
, but they must not be preceded by 0
or followed by another )
? Then this is the pattern:
(?<!0):-?\)(?!\))
Basically it's
(?<!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'
:)
:-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With