仅从字符串返回数字

时间:2016-11-13 18:16:09

标签: google-bigquery

如何仅返回Google大查询中字符串中的数字,例如:

我尝试了REGEXP_EXTRACT但没有结果。

'你好1234你好' - > 1234

由于 爱丽儿

1 个答案:

答案 0 :(得分:0)

SELECT 
  txt, 
  REGEXP_REPLACE(txt, r'\D', '') AS all_numbers_together,
  REGEXP_REPLACE(REGEXP_REPLACE(txt, r'\D', 'x'), r'x+', ' ') AS all_numbers_separated
FROM
(SELECT 'hello 1234 hello' AS txt),
(SELECT '111 hello 1234 hello 222' AS txt)