Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigQuery - Illegal Escape Sequence

I'm having an issue matching regular expression in BigQuery. I have the following line of code that tries to identify user agents:

when regexp_contains((cs_user_agent),  '^AppleCoreMedia\/1\.(.*)iPod') then "iOS App - iPod"

However, BigQuery doesn't seem to like escape sequences for some reason and I get this error that I can't figure out:

Syntax error: Illegal escape sequence: \/ at [4:63]

This code works fine in a regex validator I use, but BigQuery is unhappy with it and I can't figure out why. Thanks in advance for the help

like image 562
kshoe94 Avatar asked Oct 17 '18 15:10

kshoe94


People also ask

What is an illegal escape character?

The character '\' is a special character and needs to be escaped when used as part of a String, e.g., "\". Here is an example of a string comparison using the '\' character: if (invName. substring(j,k).

Why are illegal characters escaped?

Generally speaking, when the compiler gives you an error message, it tells you more than just "illegal escape character". It will show you the line and even the exact spot it thinks the error actually is: ? It GREATLY helps people help you if you post the ENTIRE message.


1 Answers

Use regexp_contains((cs_user_agent), r'^AppleCoreMedia\/1\.(.*)iPod')

like image 147
Mikhail Berlyant Avatar answered Sep 23 '22 11:09

Mikhail Berlyant