0

The following 2 regexes work as I expect them to, at www.regxr.com If I run a sample in the browser's console the match seems to ignore the positive lookahead. Does this mean the browser (chrome) does not support it?

let regex1 = new RegExp(/(?<=uploaded\s+).*(?=\s+new file)/gi);
let regex2 = new RegExp(/(?<!-)\d+(?=\s+-)/gi);

let input = 'Hi UPR, ' + 
'Ryan Anderson uploaded one new file to your request for Fname Lname - 743245 - CS4:' +
'Ryan Anderson - Screen Shot 2020-06-08 at 1.10.39 pm.png ' + 
'See new files'

let matches = [];
while ((matches = regex1.exec(input)) !== null) {
  console.log(`Found [${matches[0]}]. Next starts at ${regex1.lastIndex}.`);
}
Veverke
  • 9,208
  • 4
  • 51
  • 95
  • It is visible in the link you provided: "The positive lookbehind feature may not be supported in all browseres" – Igal S. Jun 08 '20 at 04:54
  • @IgalS.: I wanted to make sure: chrome not supporting it yet ? It's not a new feature, as far as I know – Veverke Jun 08 '20 at 04:58
  • As per [this](https://caniuse.com/#search=lookbehind), lookbehind regex is supported from Chrome 62 onwards. Also the issue might not be because of lookahead, instead it's because of lookbehind. – Nithish Jun 08 '20 at 05:04
  • Chrome console output: `Found [one new file to your request for Fname Lname - 743245 - CS4:Ryan Anderson - Screen Shot 2020-06-08 at 1.10.39 pm.png See]. Next starts at 151.` You test against a different string in regex101 and in your code. That is why you get different results. Use linebreaks in the string literal in your code and you will get the same result. – Wiktor Stribiżew Jun 08 '20 at 07:43

0 Answers0