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.
source
share