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