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

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -