【问题标题】:Delete greek letters in string删除字符串中的希腊字母
【发布时间】:2020-04-10 07:29:14
【问题描述】:

我正在预处理脏文本字段。我设法删除了单个字符和数字,但我仍然想完全删除希腊字母(来自公式)。 任何类型的希腊字母都可以出现在字符串中的任何位置。 有什么想法吗?

select regexp_replace(' ω ω α ω alkanediylbis alkylimino bis alkanolpolyethoxylate   the formula where       straight   branched chain alkylene group also known     alkanediyl group that has   the range       carbon atoms and     least  carbon atoms   length   and   can   the same   different and are primary alkyl groups which contain     carbon atoms each   and   can   the same   different and are alkylene groups which contain   the range   from     carbon atoms each and   and   are the same   different numerals     the range       each ', '\W+', '')

【问题讨论】:

  • 您只需要删除单个希腊字符还是任何希腊字符?
  • 任何。它们也可以作为 ωαω...

标签: postgresql regexp-replace


【解决方案1】:

[Α-Ωα-ω] 将匹配标准的希腊字母。 (请注意,这里的 Α 与拉丁语 A 是不同的字符,尽管它们看起来可能相同)。

一些常用符号在标准字母表之外,因此至少您可能希望使用[\u0370-\u03FF] 匹配整个Greek Unicode block

Unicode也有

...可能还有更多。

与其尝试列出您想要替换的所有内容,不如列出您想要保留的内容可能更容易。例如,要删除可打印的ASCII 范围之外的所有内容:

select regexp_replace(
  'ABCΑαΒβΓγΔδΕεΖζΗηΘθΙιΚκΛλΜμΝνΞξΟοΠπΡρΣσςΤτΥυΦφΧχΨψΩω123',
  '[^\u0020-\u007E]', '', 'g'
);

 regexp_replace
----------------
 ABC123

【讨论】:

    猜你喜欢
    • 2019-07-16
    • 1970-01-01
    • 2019-12-30
    • 2021-07-16
    • 2021-07-02
    • 1970-01-01
    • 1970-01-01
    • 2014-12-21
    • 2017-07-22
    相关资源
    最近更新 更多