What is the opposite of javascript match ()

If I want to match something with javascript, I can use foo.match (); but how can I check if this is not consistent ...

+3
source share
2 answers

To be more explicit, I try to use !and .test(), for example:

var hasNoMatch = !/myregex/.test(string);

Because, since spec .match()returns null in case of matches, this also works:

var hasNoMatch = !foo.match();

From the MDC documentation for.match() (much faster resource:

If the regular expression includes the g flag, the method returns Arraycontaining all matches. If there were no matches, the method returns null.

+4
source

, , test .

-, , , , . , :

// find uppercase characters
var m = s.match(/[A-Z]+/g);

// find everything except uppercase characters
var m = s.match(/[^A-Z]+/g);
+1

Source: https://habr.com/ru/post/1766619/


All Articles