Negative Lookbehind (?<!y)x
Example
let text = "Hello W3Schools";
let pattern = /(?<!Hello ) W3Schools/;
let result = pattern.test(text);
Try it Yourself »
Description
/(?<!y)x/ matches "x" only if "x" is NOT preceded by "y".
Syntax
new RegExp("(?<!y)x")
or simply:
/(?<!y)x/
Regular Expression Search Methods
In JavaScript, a regular expression text search, can be done with different methods.
With a pattern as a regular expression, these are the most common methods:
String Methods
match(pattern) | An Array of results |
matchAll(pattern) | An Iterator of results |
replace(pattern, rep) | A new String |
search(pattern) | Index of the first match |
split(pattern) | An Array of results |
RegExp Methods
pattern.exec() | An Iterator of results |
pattern.test() | true or false |
Browser Support
/(?<!y)x/
is a JavaScript 2018 feature.
ES 2018 is supported in all modern browsers since June 2020:
Chrome 63 | Edge 79 | Firefox 78 | Safari 12 | Opera 50 |
Des 2017 | Jan 2020 | Jun 2020 | Sep 2018 | Jan 2018 |