主要运用正则语法中的(积极/消极)前瞻、后顾方法,以匹配或排除特定的字符串。
可简洁明了的如下表达,以便于理解:
(?<!behind)regexp(?=ahead)
相关语法介绍:
(积极)前瞻:
(?=ahead)
Asserts that the given subpattern can be matched here, without consuming characters
/foo(?=bar)/
foobar foobaz
(消极)后顾:
(?<!behind)
(?<!...)
Ensures that the given pattern would not match and end at the current position in the expression. The pattern must have a fixed width. Does not consume characters.
/(?<!not )foo/
not foo but foo