Skip to content

Instantly share code, notes, and snippets.

@jeffskelton3
Created February 27, 2019 18:17
Show Gist options
  • Save jeffskelton3/034238f48c1a654a9553a4ef3db5abbd to your computer and use it in GitHub Desktop.
Save jeffskelton3/034238f48c1a654a9553a4ef3db5abbd to your computer and use it in GitHub Desktop.
looks through a block of text and returns all text that lives inside of handlebars along with its start/end index
const parseDatabaseFields = (input) => {
const pattern = '\{\{(.*?)\}\}';
const regex = new RegExp(pattern, 'gm');
let match;
const matches = [];
while ((match = regex.exec(input)) !== null) {
matches.push({
name: match[0],
value: match[1],
startIndex: match.index,
endIndex: match.index + match[0].length
});
}
return matches;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment