regex negative look around with 2 adjacent matches

后端 未结 2 2120
独厮守ぢ
独厮守ぢ 2020-12-21 05:02

Should be an easy question from someone out there:

If I run this JavaScript:

var regex = new RegExp(\"(?!cat)dog(?!cat)\",\"g\");
va         


        
2条回答
  •  情歌与酒
    2020-12-21 05:34

    Your regex simplifies to dog(?!cat) (because the first lookbehind consumes nothing), so it is replacing any instance of dog that is not followed by cat.

    Try the regex (?!cat).{3}dog(?!cat)

提交回复
热议问题