Search code examples
regexlooker-studiore2

Data studio regex calculated field replace after |


I'm having trouble with the formula to replace page title after |, using \| it just says "Could not parse formula". Can anyone help?

REGEXP_REPLACE(Page Title, '\|(.*)', '')

So Page name | Company name should turn to Page name


Solution

  • I suggest using

    REGEXP_REPLACE(Page Title, ' *\\|.*', '')
    

    or

    REGEXP_REPLACE(Page Title, ' *[|].*', '')
    

    You need to double the escaping backslashes or put | into a character class, and add a quantified space before to "trim" the value. You don't need the group, so I suggest removing it.