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

1378 views javascript

I've written the following line of code:

    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


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


Is it possible you meant to escape your square brackets?

posted this

Have an answer?


Please login first before posting an answer.