简体   繁体   English

在掌舵中的两个字符之间提取字符串

[英]Extracting string between two characters in helm

I am trying to extract all strings between ( and ) from values.yaml in _helper.tpl .我正在尝试从values.yaml中的_helper.tpl中提取()之间的所有字符串。

In my _helper.tpl在我的 _helper.tpl

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

my values.yaml file我的values.yaml文件

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

so i want to extract zone-base-url and some-random-text .所以我想提取zone-base-urlsome-random-text How to do this?这该怎么做?

It looks like the regex library is RE2 that does not support lookarounds of any type.看起来正则表达式库是 RE2,不支持任何类型的环视。 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) (.*?) - 第 1 组:除换行符以外的任何零个或多个字符尽可能少( [^()]*匹配除()字符以外的零个或多个字符)
  • \) - a ) char \) - a )字符

The -1 argument extracts just the Group 1 contents. -1参数仅提取第 1 组内容。

A literal backslash in the pattern must be doubled to represent a literal backslash.模式中的文字反斜杠必须加倍以表示文字反斜杠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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