slevithan / xregexp

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

Invalid Group when using a (?(DEFINE) , or using a (?&myexp) #329

Closed freddieventura closed 3 years ago

freddieventura commented 3 years ago

Hi, First of srry for my brevity but I have tendinitis so Im just writting with one hand. Due to this tendinitis I wanted to get the maximum off my keystrokes by using a PCRE compliant , Regexp library in JS , so I can use DEFINES and linebreaks in the RegExp such as https://stackoverflow.com/questions/36125759/pcre-define-statement-for-lookarounds#36130814

I'm happy so far using your libary , but I have invalid group when attempting to use define , or the Macros for groups (?<mygroup>)(?&mygroup)

console.log(XRegExp.exec('a',XRegExp('(?(DEFINE)(?<myexp1>a))(?&myexp1)')));
console.log(XRegExp.exec('a',XRegExp('(?<myexp1>a){0}(?&myexp1)')));

none of them are working. If you dont offer such a functionality It would be nice if you include it so we can get closer to PCRE on JS.

Thank you,

slevithan commented 3 years ago

XRegExp already supports linebreaks via flag x, like PCRE. It does not support DEFINE blocks and subpattern reuse via (?&name), but there is an existing issue at #190 covering those (which also describes how they might be implemented).

I don't expect to get to implementing this since it would require substantial changes to the core of XRegExp regex generation and translation into native JS regex syntax. But pull requests are welcome.

slevithan commented 3 years ago

Also note that most of the use cases for DEFINE blocks and subpattern reuse are already enabled by XRegExp.build and XRegExp.tag.