Created
February 14, 2014 09:26
-
-
Save kekscom/8998221 to your computer and use it in GitHub Desktop.
replace tags in a string by matching (primitive) object properties
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
function pattern(str, param, callback) { | |
return str.replace(/\{([\w_]+)\}/g, function(tag, key) { | |
return param[key] || tag; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment