regex - Oracle regexp cant seem to get it right -
i have values like
cr-123456 ecr-12345 bcy-499494 134-abc ecw-ecr1233 cr-123344
i want match lines not start ecr , regex doing ^((?!ecr)\w+) seems want. want replace matched values not begin ecr , replace them ecr , blanked because following doesn't seem work
select regexp_replace('cr-123344','^((?!ecr)\w+)','ecr') dual
any ideas have gone wrong ? want result be
ecr-123456 ecr-12345 ecr-499494 ecr-abc ecr-ecr1233 ecr-123344
i use substring , instr replace before dash, here answer using regexp:
aset (select 'cr-123456' dual union select 'bcy-12345' dual union select 'ecr-499494' dual union select '134-abc' dual union select 'ecw-ecr1233' dual union select 'cr-123344' dual) select a, regexp_replace(a, '^([^-]*)','ecr') b aset;
results in
a,b cr-123456,ecr-123456 bcy-12345,ecr-12345 ecr-499494,ecr-499494 134-abc,ecr-abc ecw-ecr1233,ecr-ecr1233 cr-123344,ecr-123344
Comments
Post a Comment