字符 class 与环视 - 匹配单词末尾不存在的字符。
Character class vs. Lookaround - matching non-existing character at the end of a word.
q[^x] – 匹配“question”中的“qu”。它不匹配“Iraq”,因为在“q”之后没有字符可以匹配否定字符 class。
q(?!u) 匹配“Iraq”中的“q”,但不匹配“question”中的“q”。 (这是一个负面的前瞻)。
“‘q’后没有字符供……匹配”不适用?这怎么解释呢?
来源:
https://www.regular-expressions.info/quickstart.html
"Character classes or character sets" 和 "Lookaround"。
否定前瞻断言(不是"matches")
There is no u
after q
Iraq
中的q
后面有u
吗?不,所以 q
匹配(但不是 u
!)。
反向字符class匹配
a character that is not u
after q
.
这意味着在q
、和之后必须先有一个字符,而不能是u
。所以Iraq
不匹配。
q[^x] – 匹配“question”中的“qu”。它不匹配“Iraq”,因为在“q”之后没有字符可以匹配否定字符 class。
q(?!u) 匹配“Iraq”中的“q”,但不匹配“question”中的“q”。 (这是一个负面的前瞻)。
“‘q’后没有字符供……匹配”不适用?这怎么解释呢?
来源:
https://www.regular-expressions.info/quickstart.html
"Character classes or character sets" 和 "Lookaround"。
否定前瞻断言(不是"matches")
There is no
u
afterq
Iraq
中的q
后面有u
吗?不,所以 q
匹配(但不是 u
!)。
反向字符class匹配
a character that is not
u
afterq
.
这意味着在q
、和之后必须先有一个字符,而不能是u
。所以Iraq
不匹配。