How to match words in a string that are wrapped in curly brackets using RegEx with Node.js

1 Answer

0 votes
const str = "This is a {string} with {multiple} {words} wrapped in {curly} brackets.";

// Define the RegEx pattern
const regex = /\{([^}]+)\}/g;

// Find all matches
const matches = [];
let match;
while ((match = regex.exec(str)) !== null) {
  matches.push(match[1]); // Capture group 1: text inside the brackets
}

console.log("Matches:", matches);

  
  
/*
  
Matches: [ 'string', 'multiple', 'words', 'curly' ]
      
*/
 
 

 



answered Mar 18 by avibootz
...