Masterminds / sprig

Useful template functions for Go templates.
http://masterminds.github.io/sprig/
MIT License
4.26k stars 437 forks source link

ability to escape `"` in regex functions? #141

Open asoorm opened 5 years ago

asoorm commented 5 years ago

Given the following string, how to change value of password using sprig regexReplaceAllLiteral when input and output contain " character?

{"name": "harry", "password": "foo"}

expected output:

{"name": "harry", "password": "obfuscated"}

example regex:

password\"\:\s?\".+\"
mattfarina commented 5 years ago

Sprig uses the golang regex syntax. You can find that documented at https://github.com/google/re2/wiki/Syntax. Instead of using a " to surround your string, for the regex, consider ` ... see an example at https://play.golang.org/p/62EGJpXbDKH.