Skip to content

Instantly share code, notes, and snippets.

@christothes
Created October 15, 2013 14:38
Show Gist options
  • Save christothes/6992580 to your computer and use it in GitHub Desktop.
Save christothes/6992580 to your computer and use it in GitHub Desktop.
Sample of taking some text and extracting tokens wrapped in {{ }} with regex. JSFiddle: http://jsfiddle.net/2c5LC/2/
var mail = "this is a mail with some {{special}} strings. Some of these {{special}} strings should be replaced with a {{someValue}}."
var pattern = /\{\{([\w]*)\}\}/g;
var match;
while((match = pattern.exec(mail)) !==null){
console.log(match);
console.log('match: ' + match[0] + ' at index :' + match.index);
console.log('capture: ' + match[1]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment