求教正则表达式的循环读取问题
假设字符串A="$内容A%3242$内容B%34435$内容C%......"
然后用正则表达式将$和%符号间的内容循环读取出来得到:
内容A
内容B
内容C
目前有正则函数
Public Function Extract(ByVal strMsg As String, ByVal startStr As String, ByVal endStr As String, ByVal Rete As Boolean) As String Dim rgx As Regex = New Regex("(?is)(?<=" & startStr & ").*?(?=" & endStr & ")") If Rete Then Return startStr & rgx.Match(strMsg).Value & endStr Else Return rgx.Match(strMsg).Value End IfEnd FunctionPublic Sub Extract(ByVal strMsg As String, ByVal startStr As String, ByVal endStr As String, ByVal Rete As Boolean) As String Dim rgx As Regex = New Regex("(?is)(?<=" & startStr & ").*?(?=" & endStr & ")") '这个foreach是C#语法,提供思路 foreach(Match m in rgx.Matches(strMsg)) { If Rete Then Console.WriteLine(startStr & rgx.Match(strMsg).Value & endStr) Else Console.WriteLine(rgx.Match(strMsg).Value) End If } End Function