How to replace dot in Helm template string

1.1k Views Asked by At

I'm trying to replace all the dot characters in a helm template string with \., like so:

{{- regexReplaceAllLiteral "\." "https://endpoint.index.up" "\\\." -}}

I want this to output - https://endpoint\.index\.up

This is giving me a parse error. I've tried a bunch of different combinations but nothing is replacing the dot characters. Any help appreciated!

1

There are 1 best solutions below

0
David Maze On

If you're just trying to replace a fixed string, replace will be easier to use. (This is one of the Sprig string functions so it will work with other tools that also embed the Sprig template extensions.)

{{- "https://endpoint.index.up" | replace "." "\\." -}}

It doesn't look like backslash is treated specially in the replacement string argument to regexReplaceAllLiteral so it should work so long as the replacement string argument is backslash dot; inside the double-quoted string syntax you need to double the backslash but you do not need to escape the period, so again "\\." and not "\\\.".