JS regexp (? <! X) A
Does anyone know how to convert POSIX regexp (?<!X)A to JS?
Find A only if it is not preceded by X.
+7
Fabio
source share3 answers
Just check either the beginning (ergo that there is no X) or the non-X character.
(^|[^X])A For more than one character, you can check A , and then check the text match for X followed by A, and cancel the match if it matches the second pattern.
+5
Platinum azure
source shareShort answer: you cannot.
JavaScript RegExp Object does not support negative lookbehind.
+3
Fk82
source shareTry the following:
var str = "ab"; console.log(/a(?!x)/i.exec(str)); //a var str = "ax"; console.log(/a(?!x)/i.exec(str)); //null if you need a part after "a" try:
/a(?!x).*/i 0
The mask
source share