Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Finds match/position between start and end characters
var demo = {
name: 'test',
func: function() {
return 'demo'
}
}
var string = '{{demo.description}} {({testdemo})}'
function stringPlate(str, data, startSymbol, endSymbol) {
var matches = [];
do {
var matchStart = find(arguments.startSymbol, arguments.str, matchStart ?: 1);
if(matchStart) {
matchEnd = find(arguments.endSymbol, arguments.str, matchStart);
if(!matchEnd){ return matches; }
var wordStart = matchStart+arguments.startSymbol.len();
var wordLength = matchEnd-matchStart - arguments.startSymbol.len();
writeOutput(arguments.endSymbol.len())
matches.append({
word: Mid(arguments.str, wordStart, wordLength),
start: matchStart,
end: matchStart+wordLength+arguments.endSymbol.len()
});
matchStart++;
}
} while(matchStart);
return matches;
}
//dump(stringPlate(string, demo, '{', '}'));
dump(stringPlate(string, demo, '{{', '}}'));
dump(stringPlate(string, demo, '{({', '})}'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment