簡體   English   中英

在 bigquery 中所有包含數字的單詞后添加逗號

[英]Add comma after all words containing a digit in bigquery


bigquery中,我想在字符串中的所有單詞之后添加一個逗號,如果且僅當單詞包含一個或多個數字並且該單詞當前沒有緊跟逗號時。

主要問題: 1) 對字符串中的所有示例進行匹配,而不僅僅是第一個。 2)插入逗號。

示例語句: SELECT ____________ FROM UNNEST([“5 次騎行”,“5 次騎行”,“t5 次騎行”,“5-6 次騎行”,“5 次騎行”,“5 次騎行”,“26 次騎行” 32a 騎馬”, “101-103 騎馬”, “101 - 103 騎馬”, “52b, a53a 騎馬”, “平 8,42 騎馬”, “a55 騎馬”, “5a 騎馬” , “騎行”, “52b, 騎行”]) t

狀況:
"5 the ridings" --> 5, the ridings
"騎馬 5" --> 騎馬 5,
"t5he ridings" --> t5he, ridings
"5-6 騎馬" --> 5-6, 騎馬
"flat 5 the ridings" --> flat 5, the ridings
"flat5 the ridings" --> flat5, the ridings
"26 and 32a the ridings" --> 26, and 32a, the ridings
"101-103 騎馬" --> 101-103, 騎馬
"101 - 103 the ridings" --> 101, - 103, the ridings
"52b, and a53a the ridings" --> 52b, and a53a, the ridings
"flat 8,42 the ridings" --> flat 8,42, the ridings
"a55 the ridings" --> a55, the ridings
"5a 騎馬" --> 5a, 騎馬
“騎馬”==騎馬
“52b,騎行”== 52b,騎行

這是一個正則表達式問題。 我認為這可以滿足您的需求:

SELECT u,
       regexp_replace(u, r'([^ ]*[0-9]+[^ ,]*)([ ]|$)', r'\1,\2')
FROM UNNEST(["t5he ridings", "the ridings 5", "5-6 the ridings", "flat 5 the ridings", "flat5 the ridings", "26 and 32a the ridings", "101-103 the ridings", "101 - 103 the ridings", "101 - 103 the ridings", "52b, and a53a the ridings", "flat 8,42 the ridings", "a55 the ridings", "5a the ridings", "the ridings", "52b, the ridings"]) u

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM