It feels like I've tried every single combination and Google search possible, yet I'm too dumb to figure out why this doesn't work as I want it to.
I'm trying to find all placeholders in my text, which follows the following format {var}
.
const replacementKey = new RegExp(`{${placeholder}}`, 'g');
The regular expression above results in a 'SyntaxError: nothing to repeat'. The moment I change it into the following the error goes away:
const replacementKey = new RegExp(`{ ${placeholder}}`, 'g');
The regular expression that "works" results in a search for { var}
instead of {var}
, which obviously isn't going to work. I don't want that extra space there, but I don't seem to get it right. How do I identify all {var}
in my strings, and why is that lack of space causing a syntax error?
Would appreciate any pointers I can get, and I'd love to understand why that syntax is causing the error it does.