简体   繁体   中英

Extracting string between two characters in helm

I am trying to extract all strings between ( and ) from values.yaml in _helper.tpl .

In my _helper.tpl

{{- define "firstchart.extraction" -}}
{{- regexFindAll "(?<=\()(.*?)(?=\))"  .Values.monitor.url -1 -}}
{{- end -}}

my values.yaml file

monitor:
   url: "(zone-base-url)/google.com/(some-random-text)"

so i want to extract zone-base-url and some-random-text . How to do this?

It looks like the regex library is RE2 that does not support lookarounds of any type. That means, you need to "convert" non-consuming lookarounds into consuming patterns, still keeping the capturing group in between the \( and \) delimiters:

{{- regexFindAll "\\((.*?)\\)"  .Values.monitor.url -1 -}}

Or,

{{- regexFindAll "\\(([^()]*)\\)"  .Values.monitor.url -1 -}}

Details :

  • \( - a ( char
  • (.*?) - Group 1: any zero or more chars other than line break chars as few as possible ( [^()]* matches zero or more chars other than ( and ) chars)
  • \) - a ) char

The -1 argument extracts just the Group 1 contents.

A literal backslash in the pattern must be doubled to represent a literal backslash.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM