也许会在不经意间就滑入了遗忘的角落,但在某一天,重又出现在脑海中,乘风破浪,惊喜万分的,不只自己,还有那,无从诉说的世界。

正则的进阶表达——找出(不)包含特定字符串

主要运用正则语法中的(积极/消极)前瞻、后顾方法,以匹配或排除特定的字符串。

可简洁明了的如下表达,以便于理解:

(?<!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

 
posted @ 2019-01-12 22:56  Timace  阅读(521)  评论(0编辑  收藏  举报