0

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
2
  • \2 means the sub-pattern in the second set of parentheses in the search pattern. There is only one set of parentheses in your search pattern, so there is no way this would work. Then you say everything before . Has to go, but in your example you search for specific text. Which is correct? It can't be both. Note also that period is a meta character in regular expressions, if you search for a period you must escape it. Commented Mar 17, 2017 at 2:34
  • oh thanks so much for the tip. i am new to it and i knew i must be doing it wrong. as i say in expected output, thats correct and what i am expecting and one i tried may be definitely wrong as you say Commented Mar 17, 2017 at 2:40

1 Answer 1

2

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;
Sign up to request clarification or add additional context in comments.

2 Comments

Excellent!!Exactly what i was looking for and it works :) Thanks so much
@KarthikeyanChidambaram - Glad I could help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.