[英]Regexp_Extract - Data Studio extract value after second underscore
I have a simple string separated by underscores from which I need to pull all the values after a specific underscore using a regular expression with the REGEXP_EXTRACT formula in Google Data Studio我有一个由下划线分隔的简单字符串,我需要在 Google Data Studio 中使用带有 REGEXP_EXTRACT 公式的正则表达式从特定下划线后提取所有值
The strings look like this:字符串看起来像这样:
ABC123_DEF456_GHI789-JKL274
Basically the values after the second underscore can be alphanumeric or symbols as well.基本上第二个下划线之后的值也可以是字母数字或符号。
I need to pull the values after the second underscore.我需要在第二个下划线之后提取值。 In the case of the example I gave, it would be:就我给出的例子而言,它将是:
GHI789-JKL274
Any ideas would be greatly appreciated.任何想法将不胜感激。
With your shown samples please try following regex.使用您显示的示例,请尝试使用正则表达式。
^(?:.*?_){2}([^_]*)
OR或者
REGEXP_EXTRACT(yourField, "^(?:.*?_){2}([^_]*)")
Here is the Online Demo for used regex.这是使用过的正则表达式的在线演示。
Explanation: Adding a detailed explanation for used regex here.说明:在此处添加对使用的正则表达式的详细说明。
^ ##Matching from starting of the value here.
(?: ##Opening 1 non-capturing group here.
.*?_ ##Using Lazy match to match till next occurrence of _ here.
){2} ##Closing non-capturing group here and matching its 2 occurrences.
( ##Creating 1 and only capturing group here.
[^_]* ##Matching everything before _ here.
) ##Closing capturing group here.
You need to use你需要使用
REGEXP_EXTRACT(some_field, "^(?:[^_]*_){2}([^_]*)")
See the regex demo .请参阅正则表达式演示。
Details :详情:
^
- start of string ^
- 字符串的开始(?:[^_]*_){2}
- two occurrences of any zero or more chars other than _
and then a _
(?:[^_]*_){2}
- 除了_
之外的任何零个或多个字符出现两次,然后是_
([^_]*)
- Capturing group #1: zero or more chars other than _
. ([^_]*)
- 捕获第 1 组:除_
以外的零个或多个字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.