REGEXP_SUBSTR [message #597050] |
Mon, 30 September 2013 10:14 |
fakru.y
Messages: 34 Registered: May 2007
|
Member |
|
|
Hi,
I never use REGEXP_SUBSTR function which is available in SQL. i need help on below two queries
1) i need to derive the substring enclosed with (). see the example below.
Cedilla(ç)
my output should be ç which is enclosed with ()
2) i need to derive the substring from right to left until the first dot if the pattern is like below.
xxxxx.yyyyy.zzzzz.aaaa.bbbbb
my output should be bbbbb
|
|
|
|
Re: REGEXP_SUBSTR [message #597052 is a reply to message #597051] |
Mon, 30 September 2013 11:09 |
|
Littlefoot
Messages: 21808 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
Here are some options:
SQL> with test as
2 (select 'Cecilia (x)' col from dual)
3 select
4 substr(col,
5 instr(col, '(') + 1,
6 instr(col, ')') - instr(col, '(') - 1
7 ) oldfashioned,
8 substr(regexp_substr(col, '\(\w+\)'),
9 2,
10 length(regexp_substr(col, '\(.*?\)')) - 2
11 ) regexp_10g,
12 regexp_substr(col, '\((\w+)\)', 1, 1, null, 1) regexp_11g
13 from test;
OLDFASHIONED REGEXP_10G REGEXP_11G
--------------- --------------- ---------------
x x x
SQL> with test as
2 (select 'xxx.yyy.aaa.bbb' col from dual)
3 select
4 regexp_substr(col, '\w+$') result
5 from test;
RESULT
----------
bbb
SQL>
[Updated on: Mon, 30 September 2013 11:11] Report message to a moderator
|
|
|
Re: REGEXP_SUBSTR [message #597063 is a reply to message #597052] |
Mon, 30 September 2013 12:29 |
fakru.y
Messages: 34 Registered: May 2007
|
Member |
|
|
Michal,
sorry for inconvinence, its not my intention, not to share the information to others. i always respect give and take method. i just forgot to share what i got it.
thanks for the solutions Mr.Littlefoot
|
|
|