0

I'm trying to use regexp_replace replace every occurrence of type (number) (brackets with a number inside) with the expression ('number') (add ' before and after the number and by that - transform the number into varchar).

Example -

Before change: abcde(737)sbsgs37(6)s(v)

After change : abcde('737')sbsgs37('6')s(v)

Thanks,

Ilya Golosovsky.

2
  • 1
    Sample data and desired results would really help explain what you are trying to do. Commented Nov 10, 2015 at 12:12
  • The input data is a VARCHAR2 containing alphabetical characters, punctuation and numbers - how will wrapping the numbers in quotes within a VARCHAR2 type magically change parts of the string to a NUMBER type such that wrapping them in quotes will make any difference? Commented Nov 10, 2015 at 12:37

2 Answers 2

2

You can use this one

regexp_replace('abcde(737)sbsgs37(6)s(v)', '\((\d+)\)', '(''\1''))

-> abcde('737')sbsgs37('6')s(v)

DEMO

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, thanks for the answer but this doesn't suite my case. You're targeting any number, I just need the want the ones in brackets.
I changed it (using less brackets than @pablomatico)
1

All credit for Wernfried Domscheit as he just missed one little thing. You could use this one:

regexp_replace('abcde(737)sbsgs37(6)s(v)', '(\()(\d+)(\))', '\1''\2''\3')

Tested and worked:

select regexp_replace('abcde(737)sbsgs37(6)s(v)', '(\()(\d+)(\))', '\1''\2''\3') from dual

2 Comments

Since you've already captured the parens, you could use those in the output instead of hardcoding more: select regexp_replace('abcde(737)sbsgs37(6)s(v)', '(\()(\d+)(\))', '\1''\2''\3') from dual;.
Thanks @Gary_W! You're right I just edited the answer.

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.