![](/img/trans.png)
[英]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.