Skip to main content
1 of 2
User863
  • 20.1k
  • 3
  • 20
  • 45

Using replace() method

var stringUnderTest = "/accounts/{account}/project/{project}"; var result = []; stringUnderTest.replace(/\{([^\}]*)\}/gi, function(match, string, index) { result.push({ start: index, end: index + string.length + 1 }) }); console.log(result);

User863
  • 20.1k
  • 3
  • 20
  • 45