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
source share
3 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
source

Short answer: you cannot.

JavaScript RegExp Object does not support negative lookbehind.

+3
source

Try 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
source

All Articles