-7

Suppose the following string in JavaScript,

str = "{This is between curly brackets}, {but I don't know what is between the brackets...}"

Then how do I replace() the part between the curly brackets?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
user
  • 99
  • 3

1 Answers1

1

You can use Regular expressions (regex) to achieve that.

Just use string's replace function. The first parameter will be the regex and the second one the content you want to replace all the occurrences.

str.replace(/\{[^\}]+\}/g, '{replacement}'); //"{replacement}, {replacement}"
Rod Ferreira
  • 181
  • 7