Recently, I encountered an issue with a code snippet that involves regex. Here's the specific line:
regex = /^(?<aa>[0-9]{2})-(?<bb>[0-9]{6})-(?<cc>[0-9]{6})-(?<d>[0-9])$/;
The problem arose when typescript (or perhaps webpack) raised a complaint:
Module parse failed: Error parsing regular expression: Invalid regular expression: /^(?<aa>[0-9]{2})-(?<bb>[0-9]{6})-(?<cc>[0-9]{6})-(?<d>[0-9])$/: Invalid group (18:23)
You may need an appropriate loader to handle this file type.
It appears that the issue lies with the named groups in the regex pattern. Interestingly, this regex is perfectly valid in JavaScript.
For your reference, I am using typescript version 2.9.2
I have a strong preference for employing named groups. Any suggestions on how I can ensure they compile successfully?