簡體   English   中英

用於查找包含中文字符的字符串的 BigQuery 正則表達式

[英]BigQuery regex to find string that contains chinese characters

我想找到包含任何中文字符的字符串。

我在 PostgreSQL 中有以下查詢,它按預期工作。

with tmp as (
    select '中文zz' as word
    union all
    select '中文' as word
    union all
    select 'english' as word
    union all
    select 'にほんご' as word
    union all
    select 'eng–lish' as word
)
select word,
word ~* '[\x4e00-\x9fff\x3400-\x4dbf]'
from tmp 

結果:

中文zz       true
中文         true
english     false
にほんご     false
eng–lish    false

但是,如果我在 BigQuery 中轉換這個 SQL,它不會產生相同的結果。

with tmp as (
    select '中文zz' as word
    union all
    select '中文' as word
    union all
    select 'english' as word
    union all
    select 'にほんご' as word
    union all
    select 'eng–lish' as word
)
select word,
regexp_contains(word, r'[\x4e00-\x9fff\x3400-\x4dbf]')
from tmp

結果:

中文zz      true
中文        false
english     true
にほんご     false
eng–lish    true

您可以將以下正則表達式與BigQuery結合使用:

with tmp as (
    select '中文zz' as word
    union all
    select '中文' as word
    union all
    select 'english' as word
    union all
    select 'にほんご' as word
    union all
    select 'eng–lish' as word
)
select word,
regexp_contains(word, '''[\u4E00-\u9FA5]''')
from tmp

結果是:

在此處輸入圖像描述

暫無
暫無

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

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