什么匹配这个正则表达式: qr/(?!)/; [英] What matches this regex: qr/(?!)/;
问题描述
在一个源代码中,我发现了这个正则表达式:
In one source code I found this regex:
qr/(?!)/;
我实在想不出这匹配什么.
I simply can't figure out what this matches.
老实说,绝对不明白 零宽度负前瞻断言是什么意思. - 我在 perlre 中发现的.:(
Honestly, absolutely don't understand what means the A zero-width negative look-ahead assertion. - what i found in the perlre. :(
有人可以用人类语言解释一下吗?:)
Can someone explain it in an human language, please? :)
推荐答案
合法,但完全不匹配.
(?!...)
结构是一个否定前瞻断言.详细来说,它的意思是:匹配后面的正则表达式 (...
) 应该不匹配输入字符串的位置.
The (?!...)
construct is a negative lookahead assertion. In details, it means: "match a position where the regex that follows (...
) should not match the input string".
但在这种情况下,后面的正则表达式"是空的正则表达式,它匹配所有内容.
But in this case, the "regex that follows" is the empty regex, which matches everything.
所以,这个正则表达式本质上是说匹配一个位置,其中后面的内容不能被空的正则表达式匹配"......而且无论输入字符串如何,都不可能有这样的位置.这是一个总是失败的正则表达式结构!
So, this regex essentially says "match a position where what follows cannot be matched by the empty regex"... And there can be no such position, whatever the input string. This is a regex construct which always fails!
这篇关于什么匹配这个正则表达式: qr/(?!)/;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!