Oracle regex match whitespace

南楼画角 提交于 2020-12-20 21:32:23

问题


I'm trying to change a value in oracle with regex:

input: <input id="f_alta">13/10/2016  10:10:10</input>
output: 13/10/2016  10:10:10

well, to get inside the node I use: ([\s0-9/:]+) but is no working, anyway I use: ([ 0-9/:]+) and works, why is not working with the first one?

I'm using oracle sql developer for tests.

Example:

NOT WORKING:

select REGEXP_REPLACE('<input id="f_alta">13/10/2016  10:10:10</input>', '<input id="f_alta">([\s0-9/:]+)</input>', '\1' ) from dual

WORKING:

select REGEXP_REPLACE('<input id="f_alta">13/10/2016  10:10:10</input>', '<input id="f_alta">([ 0-9/:]+)</input>', '\1' ) from dual

回答1:


Since the \s is a Perl-like construct and Oracle regex is POSIX based, it is safer to use the POSIX character class [:space:] (to include vertical whitespace) or [:blank:] (to only match spaces and tabs).

E.g. use

([[:space:]0-9/:]+)

Remember to always use POSIX character classes inside bracket expressions (so, to match one alpha character, use [[:alpha:]], i.e. the name of the class must be inside colons and double square brackets).



来源:https://stackoverflow.com/questions/40723962/oracle-regex-match-whitespace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!