-
-
Save HynesIP/625daab4b120ac7ff286bec4b2ae292b to your computer and use it in GitHub Desktop.
Find and replace double curly braces in JavaScript, example: findReplace("Hello, {{ name }}", "name", "John"); // "Hello, John"
This file contains 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
/** | |
* Format double braced template string | |
* @param {string} string | |
* @param {string} find | |
* @param {string} replace | |
* @returns {string} | |
*/ | |
function Maparameter(string, find, replace) | |
{ | |
if ((/[a-zA-Z\_]+/g).test(string)) { | |
return string.replace(new RegExp('\{\{(?:\\s+)?(' + find + ')(?:\\s+)?\}\}'), replace); | |
} else { | |
throw new Error("Find statement does not match regular expression: /[a-zA-Z\_]+/"); | |
} | |
} | |
Maparameter("{{CustomerGuid}}", "CustomerGuid", "1234-4567-7891-1234"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment