As far as I know there is no such thing as named capturing groups in JavaScript. What is the alternative way to get similar functionality?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
While you can't do this with vanilla JavaScript, maybe you can use some
Array.prototype
function likeArray.prototype.reduce
to turn indexed matches into named ones using some magic.Obviously, the following solution will need that matches occur in order:
You can use XRegExp, an augmented, extensible, cross-browser implementation of regular expressions, including support for additional syntax, flags, and methods:
s
, to make dot match all characters (aka dotall or singleline mode), andx
, for free-spacing and comments (aka extended mode).