Created
August 8, 2014 01:21
-
-
Save bricelam/a5debdbfc495eb7b116c to your computer and use it in GitHub Desktop.
A simple token-replacement template engine for PowerShell
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
function Merge-Tokens($template, $tokens) | |
{ | |
return [regex]::Replace( | |
$template, | |
'\$(?<tokenName>\w+)\$', | |
{ | |
param($match) | |
$tokenName = $match.Groups['tokenName'].Value | |
return $tokens[$tokenName] | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@craibuc Awesome. I love the
ValueFromPipeline
enhancement.