我正在尝试创建一个从字符串中返回一个或多个匹配的正则表达式,这让我疯狂。
(?<=\x03).*?(?=\r)
以上应该是寻找ETX(Char 3)的开始字符和Carriage return的结束字符。
我希望每个开始和结束字符之间的文本“阻止”。
我做错了什么?
答案 0 :(得分:0)
实际上不理我它确实有效。我想在调试一个匹配属性时看起来很困惑。一个小测试证明它没问题(在VB中)。
Dim TestString1 As String = Chr(3) & "Some Text to Extract 1" & Chr(13)
Dim TestString2 As String = Chr(3) & "Some Text to Extract 2" & Chr(13)
Dim TestString3 As String = Chr(3) & "Some Text to Extract 3" & Chr(13)
Dim TestString As String = TestString1 & " random noise " & TestString2 & " more random noise " & TestString3
Dim Matches As MatchCollection = Regex.Matches(TestString, "(?<=\x03).*?(?=\r)")
Dim Index As Integer = 0
Dim result As New StringBuilder
result.Append("No of Matches found = " & Matches.Count & vbCrLf & vbCrLf)
For Each m As Match In Matches
Index += 1
result.Append(Index & ": " & m.Groups(0).Value & vbCrLf)
Next
MessageBox.Show(result.ToString())