Regex 正则表达式排除

Regex 正则表达式排除,regex,exception,Regex,Exception,我有regexp将笑脸更改为图像。给你 (?:(?![0]:\)|:\)\)|:-\)\)))(:\)|:-\)) 重点不是在更改()和:-)时更改0:)和:))和:-)) 它在:)和:-)上运行得很好,但在0:)中仍然可以抓取:) 我的错误在哪里?所以您希望匹配:)和:-),但它们前面不能有0,后面不能有另一个)?那么这就是模式: (?<!0):-?\)(?!\)) (? 基本上是 (?<!0) : negative lookbehind; must not be preced

我有regexp将笑脸更改为图像。给你

(?:(?![0]:\)|:\)\)|:-\)\)))(:\)|:-\))
重点不是在更改()和:-)时更改0:)和:))和:-)) 它在:)和:-)上运行得很好,但在0:)中仍然可以抓取:)


我的错误在哪里?

所以您希望匹配
:)
:-)
,但它们前面不能有
0
,后面不能有另一个
?那么这就是模式:

(?<!0):-?\)(?!\))
(?
基本上是

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

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