30 December 2018 · DataFreak ·       Add to Favorites   Report

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 December 2018

Read great educational content like this and a lot more !

Members get free exclusive access to content, new courses, and discounts. Signup for a free account to write a post / comment / upvote posts. Creating an account takes less than 5 seconds and you can start earning badges & points too

Copied