正则表达式替换第二次出现的字符 [英] Regex to replace second occurrence of a character

查看:47
本文介绍了正则表达式替换第二次出现的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下格式的一些数据:

I have some data in the following format:

MM:ss:mmm 其中 MM 是分钟ss 是秒mmm 是 3 位毫秒,比如:

05:23:236

我正在尝试用点替换第二次出现的冒号:

I'm trying to replace the second occurrence of the colon with a dot:

05:23.236

我想使用 regex 模式在 Notepad++ 等编辑器中进行替换,我想出了这个正则表达式匹配我的表达:

I'd like to use a regex pattern to do a replace in an editor like Notepad++, I came up with this regex to match my expression:

 \d{1,2}:\d{1,2}:\d{1,3}

但是现在我怎样才能只得到 第二次出现的冒号 以便我可以用 dot 替换它?

But now how can I get only the second occurrence of colon so I can replace it with dot?

请注意,我正在处理的数据可能带有 1-2 位数分钟、1-2 位数秒和 1-3 位数毫秒

Notice that the data I'm working with could come with 1-2 digit minute, 1-2 digit second and 1-3 digit millisecond

推荐答案

使用这个正则表达式:

:(\d{1,3})$

替换为:

.$1

上面所做的是选择最后一个 : 后面跟着 1-3 位数的毫秒数.

What above is doing is selecting the last : which is followed by milliseconds by 1-3 digits.

演示

这篇关于正则表达式替换第二次出现的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆