Created
February 27, 2019 18:17
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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