I am creating reports in Google\'s Data Studio, and I have successfully created several custom dimensions in the past using REGEXP_MATCH
on the Keyword
Mind that in order to extract any text from REGEXP_EXTRACT
, you should define a capturing group inside the regex pattern. In short, enclose the part you need to extract with a pair of unescaped parentheses.
Now, to match img
at the start of the string you need to use ^
anchor, it matches the start of a string position.
To match 1 or more chars, use +
.
So, you may use any of the following depending on your actual rules:
REGEXP_EXTRACT(Keyword, '^img ([a-zA-Z0-9_]+)')
REGEXP_EXTRACT(Keyword, '^img\\s+(\\w+)')
REGEXP_EXTRACT(Keyword, '^img\\s+(.+)')
Details
^
- start of stringimg
- a literal substring([a-zA-Z0-9_]+)
- Capturing group 1: one or more letters, digits or _
\s+
- 1 or more whitespaces\w+
- 1 or more word chars: letters, digits or _
.+
- 1 or more chars other than line break chars.