Escape `$` in regex pattern matching in Terraform

Viewed 75

How shall I escape the dollar sign $ in Terraform pattern matching? Based on the docs I thought \$ would do:

[ for spn in group.new_spn_owners : spn if length(regexall("^\$.*", spn)) == 0 ]

but I'm getting:

The symbol "$" is not a valid escape sequence selector.
1 Answers

In HCL2 you must double escape special characters in regular expression objects:

regexall("^\\$.*", spn)

This is also true for relevant sequences e.g. \\d instead of \d.

Related