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!

Howto escape special characters if using regexp_replace & regexp_substr

oramanNov 7 2013 — edited Nov 12 2013

hello experts,

following test case

insert into querytest1 (d) values

('#1(170):[{"type":"FACEBOOK","count":0,"lastEdition":1382627403299},{"type":"GOOGLE","count":0,"lastEdition":1381825285002},{"type":"EMAIL","count":2,"lastEdition":1381826322925}] #2(0):  #3(5):-3141 #4(5):-3141 #5(5):21804 #6(7):3890750 #7(3):s11');

select regexp_replace(d, REGEXP_SUBSTR (REGEXP_SUBSTR(d, '[^ ]+', 1, 1), '[^:]+', 1, 2 ),'') from querytest1;

ERROR at line 1:

ORA-12726: unmatched bracket in regular expression

proof that []{} special characters are the problem:

delete from querytest1;

commit;

-- insert data without special characters

insert into querytest1 (d) values ('#1(170):"type":"FACEBOOK","count":0,"lastEdition":1382627403299,"type":"GOOGLE","count":0,"lastEdition":1381825285002,"type":"EMAIL","count":2,"lastEdition":1381826322925] #2(0):  #3(5):-3141 #4(5):-3141 #5(5):21804 #6(7):3890750 #7(3):s11');

select regexp_replace(d, REGEXP_SUBSTR (REGEXP_SUBSTR(d, '[^ ]+', 1, 1), '[^:]+', 1, 2 ),'') from querytest1;

REGEXP_REPLACE(D,REGEXP_SUBSTR(REGEXP_SUBSTR(D,'[^]+',1,1),'[^:]+',1,2),'')

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

#1(170)::"FACEBOOK","count":0,"lastEdition":1382627403299,:"GOOGLE","count":0,"lastEdition":1381825285002,:"EMAIL","count":2,"lastEdition":1381826322925,:"EMAIL","count":2,"lastEdition":1381826322925] #2(0):  #3(5):-3141 #4(5):-3141 #5(5):21804 #6(7):3890750 #7(3):s11

so now it works because there are no special characters []{}

is there a way to escape them?

thank you in advance.

This post has been answered by Frank Kulash on Nov 8 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 10 2013
Added on Nov 7 2013
13 comments
5,365 views