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