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: a new impossible mission ?

odabovalMar 6 2008 — edited Mar 7 2008
Hello,

We are in 10gR2, and I can do few stuffs with regular expressions in PL/SQL ... but this new case looks impossible to me ...

Here is an example of data :

WITH T AS
( select '123 HQ-2007(uz87d)' info from dual
union all
select '123a5 bcd54e-xyz 67(uuu76)' from dual
union all
select 'dfg4 4 12b-abdef g(1D3u)' from dual
union all
select 'dft de7 6 25x -abdef g(1D3u)' from dual
union all
select '7efjg k 64 4 12b- abd ef g(1D3u)' from dual
union all
select 'abc65 4 12b-fghjk hb (1D3u)' from dual
)

And, with regular expressions, I would like to get :
- in COL1, the 2 words right before hyphen '-'. If only one word before hyphen, then take it.
- in COL2, the first 2 words between hyphen and left parenthesis (. And if only one word, then take it.
- in column HYPHEN ... replace the hypen by ### (this one is very easy)


So, from the above data, here is what I would like to get :
COL1 HYPHEN COL2
---------------- -------------- -------------------------
123 HQ ### 2007
123a5 bcd54e ### xyz 67
4 12b ### abdef g
6 25x ### abdef g
4 12b ### abd ef
4 12b ### fghjk hb


I hope that my explanations are clear, and that it is possible to do that with regular expressions ..

Thanks a lot in advance,
Olivier
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 4 2008
Added on Mar 6 2008
11 comments
2,277 views