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!

Regex to exclude certain characters

laurent.demaretJun 3 2014 — edited Jun 3 2014

I would like to differentiate lines with alphanumeric (plus "_" char) strings that DO contains "%" and the ones that DOESN'T contains "%".

I came up with the following exemple but obviously my regex are not correct...

select

col a,

case

when REGEXP_LIKE( col ,'^[[:alnum:]_%]+$' ) then 'like'

when REGEXP_LIKE( col ,'^[[:alnum:]_]+$' ) then 'word'

else null

end as b

from

(

select 'eTR%t_u' col from dual

union

select '%GYh%t1' col from dual

union

select '4_OPhfk' col from dual

union

select 'aaaaaaa' col from dual

);

A           B

--------------- ---------------

%GYh%t1     like
4_OPhfk     like
aaaaaaa     like
eTR%t_u     like

This should output:

A           B

--------------- ---------------

%GYh%t1     like
4_OPhfk     word
aaaaaaa     word
eTR%t_u     like

I also tried [[:alnum:]_[^%]]+ but this does not work

Could someone give some insight on the correct regexes to use?

Thanks

This post has been answered by Boneist on Jun 3 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 1 2014
Added on Jun 3 2014
20 comments
12,307 views