REGEXP_EXTRACT in Google Data Studio; Keep Getting 'Null'

前端 未结 1 1474
刺人心
刺人心 2021-01-22 06:48

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

相关标签:
1条回答
  • 2021-01-22 07:11

    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 string
    • img - 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.
    0 讨论(0)
提交回复
热议问题