Skip to content

Instantly share code, notes, and snippets.

@basketofsoftkittens
Created March 25, 2016 19:08
Show Gist options
  • Save basketofsoftkittens/dbd5ec473f86dd9220c3 to your computer and use it in GitHub Desktop.
Save basketofsoftkittens/dbd5ec473f86dd9220c3 to your computer and use it in GitHub Desktop.
function for extracting a token value and replacing with some string
extractFormatAndReplace: function(fmt, name, replaceCb) {
var regxp = new RegExp('%\\(\\s*' + name + '+:(.+)\\s*\\)s');
if (!fmt) return '';
return fmt.replace(regxp, function findAndReplace(wholeString, match) {
return fmt.replace(wholeString, replaceCb(wholeString, match));
});
}
extractFormatAndReplace('%(hello:ValueToRetrieve)s', 'hello', function ReplaceStringWith() { return ''; });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment