Skip to main content
deleted 8 characters in body
Source Link
User863
  • 20.1k
  • 3
  • 20
  • 45

Using replace() method

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

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);

Using replace() method

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

Source Link
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);