Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google BigQuery possible to do Case-Insensitive REGEXP_Match?

In Google BigQuery I wanted to check for 'confirm' or 'Confirm':

REGEXP_CONTAINS(h.page.PagePath, r'Confirm') or
REGEXP_CONTAINS(h.page.PagePath, r'confirm'))

I am a Perl person and in Perl we do

$foo =~ /confirm/i    # case-insensitive

Does Google BigQuery have any flags to modify REGEXP_MATCH? I did not see any examples in their online docs.

like image 439
Mark Ginsburg Avatar asked Mar 23 '17 21:03

Mark Ginsburg


People also ask

Is BigQuery case insensitive?

I was stunned when some of my BigQuery queries were taking a minute or so, instead of the usual few seconds. The culprit: Case insensitive searches.

Is Google BigQuery case sensitive?

Case Sensitivity – Unlike most RDBMS, BigQuery is case sensitive, not only for string comparison, but for object names as well.

What type of regex does BigQuery use?

5) BigQuery Regex: RegexP_REPLACE RegexP_REPLACE takes three inputs, value, regular expression, and the replacement argument. It returns a string where all substrings that match regular expressions are replaced with replacement arguments.

How do you remove leading zeros in BigQuery?

If you want to remove a specific character from your String then you can use the Trimming function to do so. Based on the position of the character that you wish to remove there are three kinds of BigQuery String Functions: TRIM (value1[, value2]): It removes all the leading and trailing characters that match value2.


1 Answers

REGEXP_CONTAINS uses RE2 library, so you may use inline modifiers like this:

REGEXP_CONTAINS(h.page.PagePath, r'(?i)confirm') 
                                   ^^^^  

See RE2 docs:

(?flags)    set flags within current group; non-capturing ...
                                                                Flags
i  case-insensitive (default false)
m  multi-line mode: ^ and $ match begin/end line in addition to begin/end text (default false)
s  let . match \n (default false)
U  ungreedy: swap meaning of x* and x*?, x+ and x+?, etc (default false)

Flag syntax is xyz (set) or -xyz (clear) or xy-z (set xy, clear z).

like image 56
Wiktor Stribiżew Avatar answered Sep 20 '22 18:09

Wiktor Stribiżew