golosovsky
golosovsky

Reputation: 718

using regexp_replace to transform numbers into strings

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.

Upvotes: 0

Views: 469

Answers (2)

pablomatico
pablomatico

Reputation: 2242

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

Upvotes: 1

Wernfried Domscheit
Wernfried Domscheit

Reputation: 59642

You can use this one

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

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

DEMO

Upvotes: 2

Related Questions