Reverse slice/chop of string in Go Template

19 views Asked by At

In gotemplate (sprig), given the following strings:

one-use1-dev-01
one-two-use1-dev-01
one-two-three-use1-dev-01

I would like to "chop" off use1-dev-01 and return one, one-two or one-two-three.

use1-dev-01 will always be three segments, but dev could be stage, etc (eg, use1-stage-01).

What is the simplest way to handle this? I'm looking at trying to use regexpReplaceAll or regexpSplit but have been unsuccessful thus far.

0

There are 0 answers