Created
March 25, 2016 19:08
-
-
Save basketofsoftkittens/dbd5ec473f86dd9220c3 to your computer and use it in GitHub Desktop.
function for extracting a token value and replacing with some string
This file contains hidden or 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
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