Regex - starts with a particular string but does not end with another substring

后端 未结 2 956
你的背包
你的背包 2021-01-24 04:23

Given two strings s1 and s2, I am trying to write a regex that will match a string that starts with s1 but does not end with s2

2条回答
  •  终归单人心
    2021-01-24 05:09

    Try this:

    /^(?!.+BAD$)TEST-.*/
    

    This matches the start, goes ahead and rejects anything ending in the bad string, then matches the desired pattern.

    Here's a demo that passes all four of your tests (click "RUN TESTS" at the bottom to verify).

提交回复
热议问题