如何在bigquery中使用regexp获取值字符串



Hi我在BigQuery列中有一个字符串,就像这个

cancellation_amount: 602000
after_cancellation_transaction_amount: 144500
refund_time: '2022-07-31T06:05:55.215203Z'
cancellation_amount: 144500
after_cancellation_transaction_amount: 0
refund_time: '2022-08-01T01:22:45.94919Z'

我已经使用这个逻辑来获取取消_装载

regexp_extract(file,r'.*cancellation_amount:s*([^nr]*)')

但是输出量只有602000,我需要输出602000和144500变成不同的列

感谢您对的帮助

如果输入中的行(最终将变为列(是固定的,则可以使用多个regexp_extract来获取所有值。

SELECT
regexp_extract(file,r'cancellation_amount:s*([^nr]*)') as cancellation_amount
regexp_extract(file,r'. after_cancellation_transaction_amount:s*([^nr]*)') as after_cancellation_transaction_amount
FROM table_name

我在正则表达式中发现的一个问题是.*cancellation_amountafter_cancellation_transaction_amount不匹配。

还有一个名为regexp_extract_all的函数,它以数组的形式返回所有匹配项,您可以稍后将其分解为列,但如果您有有限的值,将它们分隔到不同的列中会更容易。

最新更新