Open xxleyi opened 4 years ago
前瞻断言(向前看)
a(?=exp) 顺序肯定环视,匹配到右侧是 exp 的字母 a
a(?=exp)
a(?!exp) 顺序否定环视,匹配到右侧不是 exp 的字母 a
a(?!exp)
后瞻断言(向后看)
(?<=exp)a 逆序肯定环视,匹配到左侧是 exp 的字母 a
(?<=exp)a
(?<!exp)a 逆序否定环视,匹配到左侧不是 exp 的字母 a
(?<!exp)a
各门编程语言对环视的支持情况不太一样,前瞻比较容易实现,后瞻难一些。
JS 正则可视化工具:https://uzitech.github.io/regexper/
Lookbehind is now an official part of the ES 2018 specification. Axel Rauschmayer gives a good introduction in his blog post.
断言(也被叫做环视)语法
前瞻断言(向前看)
a(?=exp)
顺序肯定环视,匹配到右侧是 exp 的字母 aa(?!exp)
顺序否定环视,匹配到右侧不是 exp 的字母 a后瞻断言(向后看)
(?<=exp)a
逆序肯定环视,匹配到左侧是 exp 的字母 a(?<!exp)a
逆序否定环视,匹配到左侧不是 exp 的字母 a各门编程语言对环视的支持情况不太一样,前瞻比较容易实现,后瞻难一些。
JS 正则可视化工具:https://uzitech.github.io/regexper/
Lookbehind is now an official part of the ES 2018 specification. Axel Rauschmayer gives a good introduction in his blog post.