1

Here is my string (does not work in BigQuery):

name = '0.2.4'

REGEXP_MATCH(name, '^0\\.2')

More Examples:

name1 = 'com.example.dashboard'

If we write REGEXP_MATCH(name, '^com.example') here . is wildcard entry which is means any character so if name1 is comaexample it also give true.

So to skip behavior of . we have to use \ but REGEXP_MATCH(name, '^com\\.example') gives error.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Ashish
  • 45
  • 1
  • 1
  • 7

2 Answers2

1

It does work, are you sure of your name String ?

The following query always returns true :

SELECT REGEXP_MATCH('0.2.4', '^0.2') FROM [mydataset.mytable] LIMIT 1
David
  • 5,481
  • 2
  • 20
  • 33
1

Try indicating that the pattern is a regular expression using r:

SELECT REGEXP_MATCH('0.2.4', r'^0\.2')

This returns true. The alternative is to use two slashes, as in: '^0\\.2'

Jordan Tigani
  • 26,089
  • 4
  • 60
  • 63
  • Thanks this works! why we have to say r at the starting if we dont provide r then what it means – Ashish Aug 26 '14 at 16:19
  • 'r' means 'raw'. There is a good discussion of it here: http://stackoverflow.com/questions/2241600/python-regex-r-prefix (in the context of python, but the same thing holds for bigquery SQL). – Jordan Tigani Aug 26 '14 at 16:43