JavaScript中的先行断言与后行断言

34 次浏览 1 分钟阅读 0 个喜欢
let test = 'hello world'
// 后行断言
let res = test.match(/hello(?=\sworld)/)

console.log(res)

// 先行断言
res = test.match(/(?<=hello\s)world/)

console.log(res)