Command using regex throws unmatched ')' error

Asked Sep 15, 2021·2 replies·Last activity 4 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

Hey,
I'm trying to setup a command which involves some regex, however, the result isn't what I'd expect.

What I have:

$(eval var string = "$F33H$F32a$F31v$F30n"; string.replace(/\$((\$)|[0-9a-f]{2,3}|[lh]\[.*?\]|.)/gi, ' '))

Error I get:
Invalid regular expression: /\[invalid variable]|[0-9a-f]{2,3}|[lh]\[.*?\]|.)/: Unmatched ')'

A fiddle using vanilla js, which perfectly works without throwing errors:
https://jsfiddle.net/ay7rsmv8/

How do I get this to work with nightbot? Thankful for any help.

2 replies

/\\ ``$(`` (\\$)|[0-9a-f]{2,3}\|[lh]\\[.\*?\\]|.)/gi

^

The problem is specifically this the reason it’s a nightbot only issue is because nightbot reads $( as the start of a variable so the fix would be to just use the Unicode equivalent \x24 in place of the $ sign