【问题标题】:oracle regular expression issueoracle正则表达式问题
【发布时间】:2018-03-29 14:55:20
【问题描述】:

我一直在尝试查找不可打印的记录(即 ASCII 32 到 127 之间),下面我提到了根据查询它应该打印所有 chr 小于 32 或大于 127 的记录,但它不显示带有 chr(160) 的记录,但它确实显示带有 chr(10) 的记录

select regexp_instr(a.COL, '[^[:print:]]$') as STRING_POSITION,
       a.COL, dump(col)
from tq84_compare a
where regexp_instr(a.COL, '[^[:print:]]') > 0;

insert into tq84_compare
    values (11, chr(10));

insert into tq84_compare
    values (11, chr(160));

插入 tq84_compare 价值观 (101,'在线'||chr(160)||chr(160)||chr(160));

【问题讨论】:

  • 160 码是一个硬空间,对吧?这是预期的行为,因为 [:print:] 匹配 [\x20-\x7E]、空格和所有其他可打印的 ASCII 字符。
  • 我们如何删除它,因为修剪在 chr(160) 上不起作用
  • 您的意思是您需要从条目的开头/结尾删除任何空格吗?

标签: sql regex oracle11g


【解决方案1】:

您不能将 Unicode 硬空间与 [:space:][^[:print:]]\s 模式匹配。

你可以用the following solution修剪字符串:

select regexp_replace(' some stuff  ', '^[[:space:] ]+|[[:space:] ]+$', '') as result from dual

里面的空间是硬空间。 ^[[:space:] ]+ 将匹配字符串开头的所有 ASCII 空格和/或硬空格,[[:space:] ]+$ 将匹配字符串末尾的所有 ASCII 空格字符和硬空格。

如果您想在[^[:print:]] 中添加硬空格,则需要使用替代:

select regexp_replace(' some stuff  ', '^([^[:print:]]| )+|([^[:print:]]| )+$', '') as result from dual

this online demo

【讨论】:

    猜你喜欢
    • 2014-08-17
    • 1970-01-01
    • 2018-07-11
    • 2011-01-25
    • 1970-01-01
    相关资源
    最近更新 更多