开发者

regex to replace the last digit with a hyphen and a digit

Is there a way to repl开发者_如何学Cace 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-01

Replace /file([0-9]+) with /file\1-\1

The ^ matches the beginning of a line and hence your regex doesn't match the second file01 - just get rid of it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜