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!

How to write regular expression to find desired string piece

mennanJul 4 2010 — edited Jul 5 2010
Hi All,

Suppose that i have following string piece:
name:ali#lastname:kemal#name:mehmet#lastname:cemal
I need
ali
mehmet
I use following statement
SQL> select lst, regexp_replace(lst,'(name:)(.*)(lastname)(.*)','\2',1,1) nm from (
  2    select 'name:ali#lastname:kemal#name:mehmet#lastname:cemal' as lst from dual
  3  );
 
LST                                                NM
-------------------------------------------------- --------------------------------------------------------------------------------
name:ali#lastname:kemal#name:mehmet#lastname:cemal ali#lastname:kemal#name:mehmet#
 
SQL> 
But it does not return names correctly. When i change 5th parameter(occurence) of regexp_replace built-in function(e.g. 1,2), i may get ali and mehmet respectiveley.

Any ideas about regexp?

Note : I can use PL/SQL instr/substr for this manner; but i do not want to use them. I need regexp.

Regards...
Mennan

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 1 2010
Added on Jul 4 2010
3 comments
1,643 views