1

I would like to replace a particular string format (ignoring the numbers appearing after ^).

Ex: Here, i would like to replace all occurrences of string [XYZ^abc^0^0] where any digits can come up in place of ^0^0, like [XYZ^abc^0^0] or [XYZ^abc^20^10], etc..

Input string: [XYZ^abc^0^1][dfgf^fgfgf^0^0][ggfgf^ererer^0^0][XYZ^abc^20^1][mkkfg^oorjj^0^0][XYZ^abc^0^0]

Expected output: [dfgf^fgfgf^0^0][ggfgf^ererer^0^0][mkkfg^oorjj^0^0]

I tried many combinations including the below without any success:

SELECT
  REGEXP_REPLACE('[XYZ^abc^0^1][dfgf^fgfgf^0^0][ggfgf^ererer^0^0][XYZ^abc^20^1][mkkfg^oorjj^0^0][XYZ^abc^0^0]',
                 '[XYZ^abc^\^[[:digit:]]{1,}\^[[:digit:]]{1,}\]'
                 ) "REGEXP_REPLACE" from dual

Appreciate your help!

Thanks!

2
  • Replace \[XYZ\^abc\^\d+\^\d+\] with nothing. Commented Aug 17, 2018 at 22:31
  • Awesome... thanks so much! It works..! Commented Aug 18, 2018 at 19:42

1 Answer 1

2

You need to escape the square brackets that should be treated literally. You didn't escape all the ^ characters, and you had an extra ^ character.

Also, {1,} can be written as +.

SELECT
  REGEXP_REPLACE('[XYZ^abc^0^1][dfgf^fgfgf^0^0][ggfgf^ererer^0^0][XYZ^abc^20^1][mkkfg^oorjj^0^0][XYZ^abc^0^0]',
                 '\[XYZ\^abc\^[[:digit:]]+\^[[:digit:]]+\]'
                 ) "REGEXP_REPLACE" from dual
Sign up to request clarification or add additional context in comments.

Comments

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.