JavaScript regex to find string -
i have string , 2 words dictionary , trying know if in string there words not dictionary words.
var string = 'foobarfooba'; var patt = new regexp("[^(foo|bar)]");// words dictionary var res = patt.test(string); console.log(res);//return false it should return true because in string there 'ba', return false.
same phil commented in question, have rid of character class:
[^(foo|bar)] ^-- here --^ character classes used match (or not match if use ^) specific unsorted characters.
just use:
var patt = new regexp("(?:foo|bar)");// words dictionary if want ensure string matches regex, can use:
^(?:foo|bar)+$ if want capture invalid words, can use regex capturing groups this:
^(?:foo|bar)+|(.+)$ match information
match 1 1. [9-11] `ba`
Comments
Post a Comment