Regex BigQuery-将字符串转换为数字
我正在寻找RE2接受的正则表达式语法, 将以下字符串转换为数字: “339840”->339840 “$100000”->100000 “0.75”->0.75Regex BigQuery-将字符串转换为数字,regex,google-bigquery,re2,Regex,Google Bigquery,Re2,我正在寻找RE2接受的正则表达式语法, 将以下字符串转换为数字: “339840”->339840 “$100000”->100000 “0.75”->0.75 下面的“1”->1用于BigQuery标准SQL 您可以使用cast(regexp_replace(val,r'[^\d.]','')作为数字) 参见下面的示例 #standardSQL with `project.dataset.table` as ( select "339,840" val union al
下面的“1”->1用于BigQuery标准SQL 您可以使用
cast(regexp_replace(val,r'[^\d.]','')作为数字)
参见下面的示例
#standardSQL
with `project.dataset.table` as (
select "339,840" val union all
select "$100,000" union all
select "0.75" union all
select "1"
)
select cast(regexp_replace(val, r'[^\d.]', '') as numeric)
from `project.dataset.table`
有输出
非常优雅,谢谢!