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

前端 未结 2 2094
隐瞒了意图╮
隐瞒了意图╮ 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:40
    ^one two(?!.*three)
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题