I have some records with that come with a prefix and suffix (may or may not come).
I’m trying to figure the REGEXP_REPLACE that will always return me a parametrized value.
My attempt so far is:
with teste as (
select '+123145@domain.com' as num from dual
union
select '0054321@domain.com' as num from dual
union
select '006789' as num from dual
union
select '+9876' as num from dual
union
select '13579@domain.com' as num from dual
union
select '123456789' as num from dual
)
select REGEXP_REPLACE(num,'^00(.*)\@.*$|^\+(.*)\@.*$','\1') from teste
but is not quite there.
The output of that should be:
num
12345
54321
6789
9876
13579
123456789
Try this one here
See it here online at Regexr
I am not sure what Oracle regex is able to do. Critical points could be the
\dmeaning a digit, if this is not working replace\dwith[0-9].(?:)are non capturing groups. The pattern inside is not stored in a capturing group so you can always replace with the first capturing group\1I also changed from your alternatives using
|to optional parts using?after the non capturing groups. The two brackets in your “OR” caused that the result is sometimes in group 1 (when the first alternative is matching) and sometimes in group 2 (when the second alternative is matching)