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
Use regexp_contains((cs_user_agent), r'^AppleCoreMedia\/1\.(.*)iPod')
Related
When I run a query in Biquery using the command line bq query and indicating a text_file.sql containing the query, I got this error. The query was working using the bigquery console (https://console.cloud.google.com/bigquery?xxxxxxxx). I chose UTF-8.
How should I handle this syntax error?
Please check file format is correct or not. because this issue is due file type other than UTF-8 LF in my case.
when i was change file format to UTF-8 it was running file for me.
When I try to make an __iregex call using the regular expression '^(\\. \\.)$' I get:
DataError: invalid regular expression: parentheses () not balanced
I am using PSQL backend so the django documentation states that the equivalent SQL command should be
SELECT ... WHERE title ~* '^(\\. \\.)$';
When I run this query manually through the PSQL command line it works fine. Is there some bug with Django that I don't know about that is causing this to crash?
Edit: Also, it fails for variations of this regular expression, for example
'^(S\\. \\.)$'
'^(\\. S\\.)$'
'^(\\. \\.S)$'
The solution is to replace all " " characters with \s before sending the regexp into __iregex.
I'm having an issue matching regular expression in BigQuery.
REGEXP_REPLACE(tc.metadata->>'document_number', '\D', '', 'g') = m.document_number
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: \D
This code works fine, but BigQuery is unhappy with it and I can't figure out why. Thanks in advance for the help
You need to double escape the the character in BigQuery, as the first / will be consumed by JavaScript.
Try double escaping, e.g. \\D and that should work for you.
In [1] if you scroll down you can see the escaping sequences of standard SQL and none is \D, so as Ben P says, you need to double escape to have the backslash escaping sequence. I assume it's what is missing but if you could elaborate further your question the answer would be indeed more accurate.
[1] https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#string_and_bytes_literals
I am trying to do a simple regex pattern match in Redshift
I have this code and I get the following error:
REGEXP_COUNT ( "code", '^(?=.{8}$)[A-z]{2,5}[0-9]{3,6}$' )
ERROR: Invalid preceding regular expression prior to repetition operator. The error occured while parsing the regular expression fragment: '^(?>>>HERE>>>=.{8}$)[A-'.
The pattern works fine in testing in python and online checkers I'm guessing its a REGEX language problem. I have checked in PostgreSQL documentation on REGEX to try get help as I can't find much details on actual Redshift.
Thanks,
I tried to create a regular expression for the below date format, where as I am unable to justify that, please help me out.
04-Apr-2013 [10:58:13 GMT+05:30]
This is what I came up with:
\\d{2}-\\w{3}-d{4} [\\d{2}:d{2}:d{2} \\w{3}+\\d{2}:d{2}]
Correct me where i have gone wrong.
Thanks
You have to escape the square brackets as they have a special meaning in regular expressions and also some of your digit indicators doesn't have backslash prefix. I've tested the following regex and it worked for me:
regexp:\d{2}-\w{3}-\d{4} \[\d{2}:\d{2}:\d{2} \w{3}\+\d{2}:\d{2}\]