Is there a way to replace the last digit with a hyphen and a digit.
original needs to be replaced with
file01 file01-01
file02 file02-02
With AmarGhosh I solved this
with names as
(
select '/file01/some/file01' name from dual
union all
select '/file02/another/file02' name from dual
)
select name,regexp_replace(name, '^/file0([1-9]+)','/file0\1-\1') new
NAME NEW
------------------------- -------------------------
/file01/some/file01 /file01-1/some/file01
/file02/another/file02 /file02-2/another/file02
Thanks
Thanks
Replace
^/file0([12])/with/file0\1-\1/Update: for any number of digits following file:
Replace
^/file([0-9]+)/with/file\1-\1/Update-2: for any number of
/file-01Replace
/file([0-9]+)with/file\1-\1The
^matches the beginning of a line and hence your regex doesn’t match the secondfile01– just get rid of it.