Data Studio
3.7K members online now
3.7K members online now
Ask questions about Data Studio
Guide Me
star_border
Reply

Regex: Escaping pipe character

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi there,

I am importing my Google Analytics data into the data studio. Now I want to process the label strings into new custom dimensions. The strings contain pipe separators in order to split the different pieces of information. But I am not able to create a working regex syntax that properly escapes the pipe separator.

 

Here is the REGEX I am using at the moment:

^([a-zA-Z_]*)( )(.)

 

So it basically recognises any string ([a-zA-Z_]*)

Followed by a space ( )

Followed by any character (.)

 

Instead of this third "any character" I want to have the pipe separator. I can not use it directly (|) because it is the OR-syntax. There are several ways of escaping it according to the RE2 table that is referenced in the Data Studio Help (https://github.com/google/re2/wiki/Syntax). According to the ASCII table it should be possible to escape the pipe either with

 

Octal: 174

Decimal: 124

Hex: 7C

 

But none of the variations worked. I am probably using it wrong, appreciate your help.

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Tobias L
May

Regex: Escaping pipe character

Google Employee
# 2
Google Employee

Hi Tobias,

 

Can you try doubling up the backslash character as your escape sequence?

 

E.g., REGEXP_EXTRACT(Field, 'foo(\\|)bar')

 

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Tobias L
May

Regex: Escaping pipe character

Google Employee
# 2
Google Employee

Hi Tobias,

 

Can you try doubling up the backslash character as your escape sequence?

 

E.g., REGEXP_EXTRACT(Field, 'foo(\\|)bar')

 

Regex: Escaping pipe character

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Thanks Rick, that worked.