regexp-substr

Oracle REGEXP_SUBSTR removing substring


From every String I want to remove the substring "withHugo"

I tried

SELECT REGEXP_SUBSTR('STRING-EXAMPLEwithHugo','(.+)withHugo') "REGEXPR_SUBSTR" FROM DUAL;

but it returns "STRING-EXAMPLEwithHugo" instead of "STRING-EXAMPLE". How can I REMOVE the 2nd part?


Solution

  • You want REGEXP_REPLACE here to replace "withHugo" with an empty string:

    SELECT REGEXP_REPLACE('STRING-EXAMPLEwithHugo','withHugo', '') "REGEXPR_SUBSTR" 
    FROM DUAL;