您當前的位置:首頁 > 文化

(?=[^,]) ,其中?=如何理解?

作者:由 愛吃土豆的橙子 發表于 文化時間:2020-08-20

http://www。

regular-expressions。info

/

Lookahead and lookbehind, collectively called “lookaround”, are zero-length assertions The difference is that lookaround actually matches characters, but then gives up the match, returning only the result: match or no match. They do not consume characters in the string, but only assert whether a match is possible or not. The regex q(?=u)i can never match anything. It tries to match u and i at the same position. If there is a u immediately after the q then the lookahead succeeds but then i fails to match u. If there is anything other than a u immediately after the q then the lookahead fails.

(?!) - negative lookahead

(?=) - positive lookahead (?=foo)bar —— 前面有foo的bar

(?<=) - positive lookbehind bar(?<=foo) —— 後面沒有foo的bar

(?>) - atomic group match first b match first b

標簽: match  lookahead  foo  bar  but