【问题标题】:How to use REGEX_REPLACE to search and replace partial strings in Teradata如何使用 REGEX_REPLACE 在 Teradata 中搜索和替换部分字符串
【发布时间】:2017-07-26 12:03:55
【问题描述】:

如何使用 REGEX_REPLACE 在 Teradata 中搜索和替换部分字符串。我希望能够搜索部分字符串并将其替换为空格。

例如,如果我的字符串有“Walmart and Occurrence >0/Target and Occurrence >0”,我希望能够仅搜索“Walmart”并将整个字符串替换为空格。所以我的输出应该是'/Target and Occurrence >0'

谢谢

【问题讨论】:

  • 您不是替换整个字符串,而是部分替换。规则是什么? > 0 是分隔符吗?
  • '/' 是分隔符。所以基本上我有两个用'/'分隔的字符串。 'Walmart and Occurrence >0' 是字符串 1,'Target and Occurrence >0' 是我的第二个字符串。我的要求是仅通过搜索“Walmart”将“Walmart and Occurrence >0”替换为空格。我可以有多个这样的字符串,用 / 分隔。
  • 例如,如果我的完整字符串是 'Walmart and Occurrence >0/Target and Occurrence >0/Walmart and Occurrence >3/Giant and Occurrence >2' 那么我的输出应该是 '/Target and Occurrence >0/ /巨人与出现>2.

标签: regex replace teradata


【解决方案1】:

这应该可行:

regexp_replace(x, '[^/]*Walmart[^/]*', ' ',1,0,'i') -- case insensitive
regexp_replace(x, '[^/]*Walmart[^/]*')              -- case sensitive

检查是否有'Walmart',然后用空格替换前一个斜线和下一个斜线之间的所有内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-02
    • 2010-10-10
    • 1970-01-01
    • 2015-11-13
    • 2016-01-19
    • 2021-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多