Does anyone know how translate the POSIX regexp (?<!X)A
in JS?
Find A only if not preceded by X.
Does anyone know how translate the POSIX regexp (?<!X)A
in JS?
Find A only if not preceded by X.
Simply check for either the beginning (ergo there is no X) or that there is a non-X character.
(^|[^X])A
For more than one character, you could check for A
and then check the matched text for X followed by A, and discard the match if it matches the second pattern.
Short answer: you can't.
JavaScript's RegExp Object
does not support negative lookbehind.
Try this:
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 of part after "a", try:
/a(?!x).*/i