ErgExp-lookbehind assert(后行断言)

//先行断言:先遇到一个条件,判断后面的条件是否满足
let test = 'hello world'
console.log(test.match(/hello(?=\sworld)/))

//后行断言
//判断world的前面是不是hello
console.log(test.match(/(?<=hello\s)world/))
//匹配world前面不是hello的
console.log(test.match(/(?<!hells\s)world/))

猜你喜欢

转载自www.cnblogs.com/qjb2404/p/12231726.html