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"
我要求输出字符串为'简介; 1'。
请您告诉我如何更改正则表达式以忽略文本
之后的点答案 0 :(得分: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)
答案 1 :(得分:0)
以最简单的形式,这应该有效:
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)
正则表达式在空格上匹配,而不是点。
答案 2 :(得分:0)
似乎这样做:
wr_str = Regex.Replace(wr_str, "\\.+", ";")
答案 3 :(得分:0)