Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

regular expression pattern difference between [\.\-] and [\-\.]

Mustafa KALAYCIMay 8 2018 — edited May 8 2018

Hello everyone,

I am here to ask another regular expression question again here is my sample code:

select regexp_substr('6-3', '[0-9][/\-\.][0-9from dual;

result is null.

in square brackets, we write char list that can match. so I want to check if the punctuation char is a dot, hyphen or slash but if I changed their place:

select regexp_substr('6-3', '[0-9][/\.\-][0-9from dual;

result is 6-3

since backslash is escape char I am using it before hyphen but it seems it is treated as "range" operator anyway. is that correct?

also this is not just working when source string has hyphen, if I change it to dot, it is working on every pattern.

also when I use (\-|\.) is working again.

edit: while writing this question, I tried [\-/\.] and I got "invalid range" error. so hyphen in square brackets is always treated as range operator is this correct? of course except it is not at the end of the list, then there is no range and it is working.

thanks.

This post has been answered by Paulzip on May 8 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 5 2018
Added on May 8 2018
12 comments
1,872 views