I need to get the text (if any) between curly brackets. I did find this other post but technically it wasn\'t answered correctly: Regular expression to extract text between
Create a "capturing group" to indicate the text you want. Use the String.replace() function to replace the entire string with just the back reference to the capture group. You're left with the text you want.
To extract all occurrences between curly braces, you can make something like this:
function getWordsBetweenCurlies(str) {
var results = [], re = /{([^}]+)}/g, text;
while(text = re.exec(str)) {
results.push(text[1]);
}
return results;
}
getWordsBetweenCurlies("Some random {stuff} in this {sentence}");
// returns ["stuff", "sentence"]