[英]Regex to replace second occurrence of a character
我有以下格式的一些數據:
MM:ss:mmm其中MM is minutes
, ss is seconds
, mmm is 3 digit milliseconds
,如:
05:23:236
我正在嘗試用點替換第二次出現的冒號:
05:23.236
我想使用regex
模式在像Notepad ++這樣的編輯器中進行替換,我想出了這個正則表達式來匹配我的表達式:
\d{1,2}:\d{1,2}:\d{1,3}
但是現在我怎么才能得到second occurrence of colon
所以我可以用dot
替換它?
編輯:請注意,我正在使用的數據可能有1-2位數分鍾,1-2位數字和1-3位數毫秒
嘗試這個:
string pattern = @":(?=\d{3})";
string input = "your string";
string replacement = ".";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(input, replacement);
你的正則表達式是好的,你只需要做組,然后通過再次調用它們來替換它們:
選擇:
(\d{1,2}:\d{1,2}):(\d{1,3})
更換:
$1\.$2
查找:: :(\\d{1,3})$
替換為: .\\1
或.$1
取決於您的正則表達式風格
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.