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 : matching multiple patterns.

Erikaa-OracleJun 12 2014 — edited Jun 13 2014

Hi,

I need to match all 3 patterns below:

:XXXXXXX/ or -- the string is between a colon and a forward slash

xxxxxx/ or -- the string that is before the backslash when there's no colon at the beginning.

:xxxxxxxx or the string that is after the colon when there's no backslash

CREATE TABLE REG_EXP_TEST (KEY_VALUE VARCHAR2(100));

INSERT INTO REG_EXP_TEST VALUES ('ARCHIVE_01/TGITT7_ARCH');

INSERT INTO REG_EXP_TEST VALUES ('POOL01A:ACEMT-MT01_12049_SWAP_CON/ACEMT-MT01_SWAP_STOR');

INSERT INTO REG_EXP_TEST VALUES ('POOL04A:DEFAULT');

COMMIT;

This is the sql I'm using but it matches only the first and second case and is ignoring the third case (:xxxxxxxx).  Is there a way that it can match these 3 patterns?.  In red is the string that I need to match.

SELECT KEY_VALUE, REGEXP_SUBSTR(KEY_VALUE,'[^:]+(?/)',1,1,'i') as project

FROM REG_EXP_TEST;

KEY_VALUE                                                                                                  PROJECT                                                                                      

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

POOL04A:DEFAULT                                                                                      
POOL01A:ACEMT-MT01_12049_SWAP_CON/ACEMT-MT01_SWAP_STOR ACEMT-MT01_12049_SWAP_CON/                                                                     
ARCHIVE_01/TGITT7_ARCH                                 ARCHIVE_01/                                                                                    

Thanks for your help.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 11 2014
Added on Jun 12 2014
4 comments
1,819 views