matching a line that doesn't contain specific text with regular expressions

前端 未结 2 2097
隐瞒了意图╮
隐瞒了意图╮ 2021-01-04 19:03

I want to do the following with regular expressions but not sure how to do it. I want it to match one two when one two is the beginning of the line

2条回答
  •  有刺的猬
    2021-01-04 19:42

    You need a negative lookahead assertion - something like this:

    /^one two(?!.*three)/m
    

    Here's a tutorial on lookahead/lookbehind assertions

    Note: I've added the 'm' modifier so that ^ matches the start of a line rather than the start of the whole string.

提交回复
热议问题