I can't find an answer in either BigQuery Reference or re2 wiki.
In all the examples for Regex section in the BigQuery Reference there is an 'r' before every regex, but I can't find anywhere the meaning of it. For example:
REGEXP_EXTRACT(word,r'(\w\w\'\w\w)')
It seems to me as a typecast of 'regex' or something, because it allows for '\' and ''' in the following string.
Thanks to anyone who knows and posts an answer to this :)
From Wikipedia "A few languages provide a method of specifying that a literal is to be processed without any language-specific interpretation. This avoids the need for escaping, and yields more legible strings."
http://en.wikipedia.org/wiki/String_literal#Raw_strings
For example, this looks like a valid regex, but the escapes get miss-interpreted:
SELECT REGEXP_EXTRACT("ab'cd", '(\w\w\'\w\w)')
Error: Invalid string literal: '(\w\w\'\w\w)'
I can fix this in two ways. With a raw string, or escaping the escapes:
Escaping the escapes:
SELECT REGEXP_EXTRACT("ab'cd", '(\\w\\w\'\\w\\w)')
ab'cd
Raw string:
SELECT REGEXP_EXTRACT("ab'cd", r'(\w\w\'\w\w)')
ab'cd
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With