30 Dec 18 · DataFreak ·       Add to Favorites  

How to remove only letters from a string in BigQuery?

For example:

XXXX123456
AAAA123456789
XYZR12345678
ABCD1234567
1111
2222

I want the end result to look like:

123456
123456789
12345678
1234567
1111
2222

Solution:

You can use regexp_replace():

select regexp_replace(str, '[^0-9]', '')

DataFreak

posted on 30 Dec 18

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds

Copied