console.log showing subpattern in regex instead of the actual regex
st-clair-clarke opened this issue · 2 comments
st-clair-clarke commented
I have the following:
const baseRegex = XRegExp.tag('gimx')`A-Z0-9`
console.log({baseRegex}) // expected => {baseRegex: /A-Z0-9/gim}
const interimRegex = XRegExp.tag(baseRegex.flags)`[${baseRegex}]+`
console.log({interimRegex}) // UNEXPECTED => {interimRegex: /[{{subpattern0}}]+/gim}
Why does the interpolation ${baseRegex} results in {{subpattern0}}. From previous discussions, it should not.
slevithan commented
It's bug #192 that's been there since the introduction of XRegExp.tag, and which prevents interpolating regexes inside character classes. Two potential paths forward are mentioned in that issue:
- Making interpolation into a character class a syntax error (to avoid unexpected surprises like breaking out of a character class with an unescaped
], or the meaning of regex symbols changing in character class context). - Matching probably most users' preferences by allowing it in the way you're expecting here (possibly with some level of protection).
Pull requests are welcome.
st-clair-clarke commented
Thanks. Option 2 seems the better of the two.