0

I want to use regexp_replace() to replace the string

name1-01.name2-02.1

to

name1.01-name2.02.1

How to use the regex here?

  • Could you please tell which parts are subject to change? For example, 'name1' is always 'name1' or it can be 'name23' and 'somethingelse543', too? Additionally, explaining the rules for the change would help a lot. – dezso Nov 27 '13 at 15:09
1
select regexp_replace('name1-01.name2-02.1','(.*)-(\d+)\.(.*)-(.*)','\1.\2-\3.\4');

Assuming:

  • Everything before the first '-' can contain anything but '-'.
  • There's always a number after the first '-'
  • 'name2' doesn't contain a '-'

Just guessed your requirements, basically. Might be wise for you to read a regular expression tutorial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.