slevithan / xregexp

Extended JavaScript regular expressions
http://xregexp.com/
MIT License
3.31k stars 278 forks source link

Does not polyfill negative lookbehind in Safari #351

Closed kettanaito closed 1 year ago

kettanaito commented 1 year ago

Hey 👋

Thanks for writing this library.

I'm trying to use it to polyfill some of the missing RegExp features in Safari, like negative lookbehind.

Steps to reproduce

import XRegExp from "xregexp";

console.log(XRegExp("/\r(?!\n)|(?<!\r)\n/"));

Result in Safari:

Invalid regular expression: invalid group specifier name

— Open in CodeSandbox

I believe this is caused by new RegExp(generated.pattern, ...) constructor in the source of xregexp. It looks like it constructs a new RegExp, using the native class, providing it with the unsupported pattern string in Safari.

Expected behavior

I'd expect negative lookbehind to work in Safari. Let me know if I understood the intention behind this library wrong.

kettanaito commented 1 year ago

Found #77. I suppose that closes this one.