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

后端 未结 2 958
你的背包
你的背包 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条回答
  •  旧时难觅i
    2021-01-24 05:24

    You can use startsWith and endsWith

    let arr = [`TEST-101`, `TEST-SOME-DESC`,`TEST-101-BAD`,`TEST-SOME-DESC-BAD`]
    
    arr.forEach(e=>{
      console.log(e, e.startsWith('TEST') && !e.endsWith('BAD'))
    })

提交回复
热议问题