Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle regex match whitespace

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
like image 353
ZiTAL Avatar asked Feb 05 '23 16:02

ZiTAL


1 Answers

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).

like image 191
Wiktor Stribiżew Avatar answered Feb 08 '23 14:02

Wiktor Stribiżew