https://regex101.com/r/sB9wW6/1
(?:(?<=s)|^)@(S+) <-- the problem in positive lookbehind
(?:(?<=s)|^)@(S+)
Working like this on prod: (?:s|^)@(S+), but I need a correct start index (without space).
prod
(?:s|^)@(S+)
Here is in JS:
var regex = new RegExp(/(?:(?<=s)|^)@(S+)/g);
Error parsing regular expression: Invalid regular expression: /(?:(?<=s)|^)@(S+)/
What am I doing wrong?
UPDATE
Ok, no lookbehind in JS :(
But anyways, I need a regex to get the proper start and end index of my match. Without leading space.
Make sure you always select the right regex engine at regex101.com. See an issue that occurred due to using a JS-only compatible regex with [^] construct in Python.
[^]
JS regex - at the time of answering this question - did not support lookbehinds. Now, it becomes more and more adopted after its introduction in ECMAScript 2018. You do not really need it here since you can use capturing groups:
var re = /(?:s|^)@(S+)/g; var str = 's @vln1 @vln2 '; var res = []; while ((m = re.exec(str)) !== null) { res.push(m[1]); } console.log(res);
2.1m questions
2.1m answers
60 comments
57.0k users