regex - Oracle regexp_substr, regexp_replace -
i need extract substring via oracles regexp_substr method.
so far use
select regexp_substr('td_schemaneu_576','[^td_]+[a-za-z]') dual ; which works fine, since returns expected sub string between 'td_' && '_576':
schemaneu but if the source string doesn't contain string 'td_' regex returns string instead of null
the following returns abc instead of null
select regexp_substr('abc_def_ghi1024','[^td_]+[a-za-z]') dual ;
[^td_] means "any character, except t, d or _".
you might want use regex_replace , capturing groups:
regex_replace('td_schemaneu_576', 'td_([a-za-z]+)', '\1') the \1 backreference, pointing in first capturing group, ie first set of parenthesis in regex.
Comments
Post a Comment