regexp排除

Vla*_*lad 6 regex exception

我有正则表达式将表情符号改为图像.这里是

(?:(?![0]:\)|:\)\)|:-\)\)))(:\)|:-\))
Run Code Online (Sandbox Code Playgroud)

关键是不要改变0 :)和:))和:-))同时改变:)和:-)它与:))和:-))相当不错但不知何故仍然抓住:)在0 :)

哪里是我的错?

pol*_*nts 5

所以,你想匹配:):-),但它们必须不被前面0或后面另一个)?然后这是模式:

(?<!0):-?\)(?!\))
Run Code Online (Sandbox Code Playgroud)

基本上就是这样

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

例:

$ echo ':) :-) ok 0:) :)) :-)) 0:-)) 0:-) : )' | \
> perl -lne'print $1 while /(?<!0)(:-?\))(?!\))/g'
:)
:-)
Run Code Online (Sandbox Code Playgroud)