Ad
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?
Ad
Answer
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.
Ad
source: stackoverflow.com
Related Questions
- → How to replace *( in a string
- → Regex extract string after the second "." dot character at the end of a string
- → CodeMirror regex doesn't match behavior typical Javascript regex parser
- → JS Get multiple links in a string
- → Using capture group $1 to access object's key value
- → Difference between /(a|b)/ and /[ab]/ in JavaScript split() using regex
- → In Nginx, how to match and entire URL and Query String and redirect to a URL and Query String
- → Reorder lines in a string based on first two numbers inside
- → How to manage URL with or without ? and /
- → Not sure why this Regex is returning true
- → Laravel extract excerpt from content using tinymce
- → Cannot get my multiple regex working for specific case in URL structure
- → laravel5.1 validate number
Ad