简体   繁体   中英

How to extract second, third, forth and.... number with regexp_extract

I can extract the first number value from a column with the command

CAST(REGEXP_EXTRACT(column, "(\\d+)") AS NUMBER )

but I have a problem with a case where I need to extract the second and the following numbers like 45,35 etc.

xxx 54 | yyy 45 | zzz 35|

please help :(

You can use REGEXP_EXTRACT_ALL , but it will return an array of all the numbers that were found in the string.

Here is how you can UNNEST it and cast them as numbers against the rows in BigQuery :

Select 
table1.*,
CAST(arr AS INT64) as arr 
FROM table1, UNNEST(REGEXP_EXTRACT_ALL(column, "(\\d+)" )) as arr

Screenshot of how I tested it in BQ

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM