I'm trying to replace the value of the version property in the following yaml structure.
My reason for using regex rather than parsing the yaml is that I need to write it back again. If I parse it and then write it back it'll loose it's existing formatting.
environments:
local:
values:
- kubeContext: default
- surfScreenshotter:
installed: false
version: 0
- whoamiMn:
installed: false
version: 0
dev:
values:
- kubeContext: nuc
- surfScreenshotter:
installed: false
version: 0
- whoamiMn:
installed: false
version: 0
My kotlin code
val regex = """environments:
|.*
| $environment:
| values:
|.*
| - $projectName:
|.*
| {10}version: (\S+)
""".trimMargin().toRegex(MULTILINE)
val updatedHelmfile = regex.replaceFirst(helmfileContent, version)
$environment can be either "local" or "dev" and projectName can be "surfScreenshotter" or "whoamiMn".
Nothing is matched. Anyone got an idea how to make this work?