Last active
May 14, 2021 13:43
-
-
Save dadhi/109b84ecb7dffe29f9bc to your computer and use it in GitHub Desktop.
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
<# | |
Token-replacement template engine for PowerShell courtesy to http://www.bricelam.net/2012/09/simple-template-engine-for-powershell.html | |
Usage: | |
Merge-Tokens 'Hello, $target$! My name is $self$.' @{ target = 'World'; self = 'Brice' } | |
#> | |
function Merge-Tokens($template, $tokens) | |
{ | |
return [regex]::Replace($template, '\$(?<token>\w+)\$', | |
{ param($match) $tokens[$match.Groups['token'].Value] }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment