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 - REGEXP_REPLACE

user13117585Nov 17 2011 — edited Nov 18 2011
Hello everyone,

I have a small issue with regular expression. Look at the following example:
WITH T as (SELECT 'ABC' as a  FROM dual
           UNION ALL 
           SELECT 'ABC.Test' FROM DUAL
           UNION ALL
           SELECT 'XXX' FROM DUAL
)
SELECT a, 
       regexp_replace(a, '^(ABC)?(\.)?(.+)$','ABC.\3')
  FROM t
Don't pay attention to the regexp I did. It's wrong.
What I want is :
- when my string start with something else than ABC, it is replaced by the same string with ABC. in front of it.
- When the string starts with ABC. something, nothing changes
- When the string is ABC (without the final dot) the string doesn't change.

Any idea how I can do that using regexp_replace? (I'm using Oracle 10g)

Thanks
This post has been answered by Solomon Yakobson on Nov 17 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 16 2011
Added on Nov 17 2011
29 comments
276 views