How can I invert a regular expression in JavaScript?

后端 未结 4 1961
野趣味
野趣味 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:30

    Here's an example of an inequality. First I isolate the operator '<', later the operands 'a' and 'b'. Basically, I take the direct expression, include it into right parentheses, invert the latter by '^' and finally embed the resulting expression into square brackets, 'cause the '^' at the beginning would be interpreted differently.

    var _str = "a < b" ;
    var _op = /

    P.s.: I just added the blank space in the inverse expression, in order to retrieve exact matching for the operands.

提交回复
热议问题