问题描述
我有以下格式的一些数据:
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 withthis 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.
这篇关于正则表达式替换第二次出现的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!