Ashish
Ashish

Reputation: 45

How to search wildcard . as a string in Big Query

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.

Upvotes: 1

Views: 2765

Answers (2)

Jordan Tigani
Jordan Tigani

Reputation: 26637

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'

Upvotes: 1

David
David

Reputation: 5511

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

Upvotes: 1

Related Questions