使用regexp_extract从BigQuery中删除单引号和双引号

时间:2022-01-04 15:35:32

I'm a total noob with regexp. All I want to do is to remove the single and double quotes from a string in BigQuery. I can remove the single and double quotes at the beginning of the string, but not the end:

我是regexp的总菜鸟。我想要做的就是从BigQuery中的字符串中删除单引号和双引号。我可以在字符串的开头删除单引号和双引号,但不删除结尾:

SELECT regexp_extract(foo, r'\"new_foo\":\"(.*?)\"') AS new_foo FROM [mybq:Schema.table]

SELECT regexp_extract(foo,r'\“new_foo \”:\“(。*?)\”')AS new_foo FROM [mybq:Schema.table]

All I get is Null but without regexp_extract I have expected results. Help is appreciated.

我得到的只是Null但没有regexp_extract我有预期的结果。感谢帮助。

2 个解决方案

#1


2  

Try something like below

尝试类似下面的内容

SELECT REGEXP_REPLACE(foo, r'([\'\"])', '') AS new_foo 
FROM [mybq:Schema.table]

#2


0  

Your regex expression should be like /["']/g

你的正则表达式应该像/ [“'] / g

And your are using different method to get the expected result. Try REGEXP_REPLACE('orig_str', 'reg_exp', 'replace_str')

并且您正在使用不同的方法来获得预期的结果。尝试REGEXP_REPLACE('orig_str','reg_exp','replace_str')

Something like this:

像这样的东西:

SELECT REGEXP_REPLACE(word, /["']/g, '')AS new_foo 
FROM [mybq:Schema.table]

#1


2  

Try something like below

尝试类似下面的内容

SELECT REGEXP_REPLACE(foo, r'([\'\"])', '') AS new_foo 
FROM [mybq:Schema.table]

#2


0  

Your regex expression should be like /["']/g

你的正则表达式应该像/ [“'] / g

And your are using different method to get the expected result. Try REGEXP_REPLACE('orig_str', 'reg_exp', 'replace_str')

并且您正在使用不同的方法来获得预期的结果。尝试REGEXP_REPLACE('orig_str','reg_exp','replace_str')

Something like this:

像这样的东西:

SELECT REGEXP_REPLACE(word, /["']/g, '')AS new_foo 
FROM [mybq:Schema.table]