Search code examples
regexlooker-studiore2

REGEX_EXTRACT in Data Studio not matching Regex pattern


I am using REGEX pattern -\\s.+?_{1} To match FY22_1-103_Evergreen - US Territories (US Virgin Islands)_ Quitters_Video Views_Twitter Feed_07.01.21-09.15.21

But the results are null in the table the regex function is returning to. I'm not sure if I just don't fully understand the limitations of re2, or if I am missing something else.

EDIT:

I ended up trying a raw string R"(-\s.+?_{1})" which worked.


Solution

  • You can use a regex with a capturing group like

    -\s+([^_]+)_
    

    See the regex demo.

    Details:

    • - - a hyphen
    • \s+ - one or more whitespaces
    • ([^_]+) - Capturing group 1: one or more chars other than an underscore
    • _ - an underscore.