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!

Using regexp_replace to remove characters only at the start of a string

user479119Oct 27 2014 — edited Oct 27 2014

I want to be able to remove characters from a string only up to the first numeric value.  If there are any after the numeric I want to keep them.

e.g. 'AB1234'  should become '1234',     'AB1234C' should become '1234C'.

There also could be spaces and other types of characters at the start.  I have tried this:

select

regexp_replace('ABC1234', '[^[:digit:]]'),

regexp_replace('AB 1234', '[^[:digit:]]'),

regexp_replace('AB 01234', '[^[:digit:]]'),

regexp_replace('AB1234C', '[^[:digit:]]'),

regexp_replace('^1234', '[^[:digit:]]'),

regexp_replace('*#1234Z', '[^[:digit:]]')

FROM DUAL

For all except 'AB 01234' it returns '1234' so it only keeps the numeric.    For 'AB 01234' it correctly returns '01234'

The ones incorrect are those with a character after the numeric e.g. 'AB1234C'.

I know I am missing something here, can anyone please help with this?

Thanks

This post has been answered by Karthick2003 on Oct 27 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 24 2014
Added on Oct 27 2014
7 comments
3,874 views