1

Struggling with Helm to match the word from its beginning to the last occurance of -.

I tried {{- printf "%s" .Release.Name | regexFind "[^-]*$" -}}, but it prints from the last occurrance to the end of the word.

Expected

input : hello-world-here => output: hello-world

input : hello-world-here-and-there => output : hello-world-here-and

Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254

1 Answers1

4

Big thanks to @Wiktor Stribiżew for his hints.

After a lot of investigation, I realized that the Regex is correct, but the signature of function is amazing :

{{- regexReplaceAll "-[^-]*$" .Release.Name "" -}}

and NOT :

 {{- regexReplaceAll "-[^-]*$"  "" .Release.Name -}}
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254
  • That is why I put `-` in between the regex and replacement patterns, I took it for an input variable in the piped notation. – Wiktor Stribiżew Jul 27 '19 at 19:08
  • 5
    To make it a bit more clear, the order of the arguments is: pattern, input string, replacement pattern. – ssc327 Oct 29 '20 at 02:46