Oracle: Regex replace for multiple replacements on a pattern

I am trying to find a solution but somehow i am getting wrong output (referred some online solutions and confusing myself :( ). please advise where i am going wrong.

var := 'test_1_file1.extn1 test_1_file2.extn2'
select regexp_replace(var,'(test_1*.).*$','\2') from dual;

Expected output: everything should be removed before .operator

extn1 extn2

Upvotes: 0

Views: 1809

Answers (1)

Gurwinder Singh
Gurwinder Singh

Reputation: 39537

Try this:

SELECT
  regexp_replace( var, '([^ ]*\.)', '' ) replaced
FROM dual;

If the word must start with test_1:

SELECT
  regexp_replace( var, '(test_1[^ ]*\.)', '' ) replaced
FROM dual;

Upvotes: 2

Related Questions