【问题标题】:SQL - REGEX Match the whole word if it has an @ symbol in itSQL - REGEX 如果它有一个@符号,则匹配整个单词
【发布时间】:2021-12-28 17:04:21
【问题描述】:

所以我使用的是 Snowflake,特别是 REGEXP_REPLACE 函数。我正在寻找一个正则表达式,它将匹配文本字段中带有@符号的任何单词。

例子:

RAW_DATA CLEANED_DATA
here is a sample and then an email@gmail.com here is a sample and then an xxxxx
abc@test.com xxxxx

到目前为止我尝试过的是:

Select regexp_replace('ABC@gmail.com' , '(([a-zA-Z]+)(\W)?([a-zA-Z]+))', 'xxxxxxx') as result;

结果:

xxxxxxx@xxxxxxx.xxxxxxx

【问题讨论】:

    标签: sql regex snowflake-cloud-data-platform


    【解决方案1】:

    你可以使用

    Select regexp_replace('here is a sample and then an email@gmail.com' , '\\S+@\\S+', 'xxxxx') as result;
    

    这里,

    • \S+ - 一个或多个非空白字符
    • @ - 一个 @ 字符
    • \S+ - 一个或多个非空白字符

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-24
      • 2021-06-27
      • 1970-01-01
      • 2015-11-22
      相关资源
      最近更新 更多