XRegExp: "Unmatched ')'" Yet everything appears to be balanced

1378 views javascript
-1

I've written the following line of code:

XRegExp.exec(data,
    XRegExp('<!-- @\[(?<component>[\w+])[\(*(?<classes>[\w+])*\)]*\] -->', 'g'))

As you can see it is using the XRegExp library so I can use named groups other PCRE features.

I'm getting the error:

syntaxError: Invalid regular expression: /<!-- @[(?<component>[w+])[(*(?<classes>[w+])*)]*] -->/: Unmatched ')'

However, I don't understand where the unmatched ) is. As far as I can tell, all brackets that need to be escaped should be and all the ones that shouldn't are not.

Here is the string I am trying to match:

<!-- @[NoteBlock(warning)] -->

these should also match:

<!-- @[NoteBlock(warning, high-level)] -->

<!-- @[NoteBlock] -->

This should not match:

<!-- @[(warning, high-level)] -->

answered question

1 Answer

11

My understanding is you can't capture inside an array of characters.

[\(*(?<classes>[\w+])*\)]*

Is it possible you meant to escape your square brackets?

posted this

Have an answer?

JD

Please login first before posting an answer.