Skip to content

Instantly share code, notes, and snippets.

@malko
Created February 21, 2012 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malko/1878729 to your computer and use it in GitHub Desktop.
Save malko/1878729 to your computer and use it in GitHub Desktop.
string placeholder replacement function
printReplace=function(str,vars){
if( typeof vars !== 'object' ){
return str;
}
return str.replace(/(%+)([a-z0-9_-]+)/g,function(m,p,k){
if( p.length === 1 && typeof vars[k] !== 'undefined'){
return vars[k] || '';
}
return m;
});
}
String.prototype.printReplace = function(vars){ return printReplace(this,vars); };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment