When using lookarounds in regex, the text is not consumed and the regex index does not move when their patterns are matched. For more information, check out Lookarounds Stand their Ground.
To match the text, you still need to use a consuming pattern such as \w+
for word matching. Alternatively, you can use \S+
for one or more non-whitespace characters. If any characters, including line breaks, need to be matched, use .+
(matches 1 or more characters other than line break characters) or [^]+
(matches even line breaks).
var text = "match100match match200match match300match";
var matches = text.match(/match(?!100(?!\d))\w+match/g);
console.log(matches);
Details of the Pattern
match
- a literal substring
(?!100(?!\d))
- a negative lookahead that fails the match if immediately to the right there is the substring 100
not followed by a digit. If you want to fail matches where the number starts with 100
, remove the (?!\d)
lookahead.
\w+
- 1 or more word characters (letters, digits, or _
)
match
- a literal substring
Check out the online regex demo.