How can I invert a regular expression in JavaScript?

后端 未结 4 1964
野趣味
野趣味 2020-11-27 03:46

I have a string A and want to test if another string B is not part of it. This is a very simple regex whose result can be inverted afterwards.

I could do:



        
4条回答
  •  广开言路
    2020-11-27 04:28

    If what you're searching for really isn't more complicated than a simple string like "foobar":

    if (yourString.indexOf("foobar") === -1) {
      // ...
    }
    

    http://www.w3schools.com/jsref/jsref_indexOf.asp

提交回复
热议问题