0

This regular expression: /\{(\w+)\}/g returns ["{name}", "{color}"] and ignores my parenthesis around (\w+)

Why doesn't this work? What is the correct regular expression?


Token replacement:

const item = {
  name: 'foo',
  color: 'bar'
};

let str = `'{name} - {color}'`

console.log( str.match( /\{(\w+)\}/g ) );
Praveen Reddy
  • 7,295
  • 2
  • 21
  • 43
neaumusic
  • 10,027
  • 9
  • 55
  • 83

0 Answers0