Skip to content

Instantly share code, notes, and snippets.

@santisq
Created May 8, 2024 20:15
Show Gist options
  • Save santisq/e3ecfbf19ce2d385d0ef0dec1f0d4c8b to your computer and use it in GitHub Desktop.
Save santisq/e3ecfbf19ce2d385d0ef0dec1f0d4c8b to your computer and use it in GitHub Desktop.
$map = @{
color = 'red'
person = @{
firstname = 'Bob'
lastname = 'Smith'
}
gender = 'his'
}
$template = @'
This a block of text. Here is a color {{ color }}.
{{ person.firstname }} should be able to read this with {{ gender }} name in it.
'@
[regex]::Replace($template, '\{{\s*(.+?)\s*\}}', {
param($s)
foreach ($i in $s.Groups[1].Value.Split('.')) {
$map = $map[$i]
}
$map
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment