[英]I need a recursive function to remove periods of time from other periods of time
[英]regex code to remove periods
Dim wr_str as string
Dim str as string = "Introduction........................1"
Dim no As Match = Regex.Match(wr_str, "(^.*?)(\s*)([0-9]+)\s*$")
wr_str = Regex.Replace(wr_str, "(^.*?)(\s*)([0-9]+)\s*$", no.groups(1).value & no.groups(3).value)
Input string = "Introduction........................1"
我要求輸出字符串為“ Introduction; 1”。
您能否讓我知道如何更改正則表達式以忽略文本后的點
您可以像這樣使用捕獲組:
Dim myMatch = Regex.Match("Introduction.............1", "(^.*?)\.*([0-9]+)\s*$")
Dim res2 = myMatch.Groups(1).Value + ";" + myMatch.Groups(2).Value
點用\\.*
捕獲,並且不用於最終的字符串創建。
編輯:要匹配您的代碼上下文:
Dim no as Match = Regex.Match("Introduction.............1", "(^.*?)\.*([0-9]+)\s*$")
wr_str = Regex.Replace(wr_str, "(^.*?)(\.*)([0-9]+)\s*$", no.Groups(1).Value.Replace(".", "").Trim() & ";" & no.groups(2).value)
以最簡單的形式,它應該可以工作:
Dim wr_str as string
Dim str as string = "Introduction........................1"
Dim no As Match = Regex.Match(wr_str, "(^.*?)(\.*)([0-9]+)\s*$")
wr_str = Regex.Replace(wr_str, "(^.*?)(\.*)([0-9]+)\s*$", no.groups(1).value & ";" & no.groups(3).value)
正則表達式匹配空白,而不是點。
看來這可以做到:
wr_str = Regex.Replace(wr_str, "\\.+", ";")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.