0

I am trying to get a substring which is inside curly brackets by using regular expression.

Assuming that I have the following string:

"This is a {nice} text to search for a {cool} substring".

I'd like to be able to search for nice and cool

Declan Lynch
  • 3,345
  • 17
  • 36
user2502490
  • 43
  • 1
  • 6

1 Answers1

4

Try as follows:

var myString = "This is a {nice} text to search for a {cool} substring",
  pattern = /[^{}]*(?=\})/g;

console.log(myString.match(pattern));
mplungjan
  • 169,008
  • 28
  • 173
  • 236
taxicala
  • 21,408
  • 7
  • 37
  • 66