我有一个 12 MB 的文件,我将其数据复制到 RichTextBox1 中进行处理。完成大约需要 4 秒,但有人告诉我使用 (RegexOptions.Compiled) 使其更快,但我看不出两者之间有什么区别两个都。
Debug.Print(ParseData2(RichTextBox1.Text, "start", "end"))
这是功能,但我评论了我在哪里做测试
Function ParseData2(strData As String, ByVal sStart As String, ByVal sStop As String)
'Dim r As New Regex(sStart & "(.*?)(" & sStop & "|$)", RegexOptions.Multiline Or RegexOptions.IgnoreCase Or RegexOptions.Compiled)
Dim r As New Regex(sStart & "(.*?)(" & sStop & "|$)", RegexOptions.Multiline Or RegexOptions.IgnoreCase)
Dim matches = r.Matches(strData)
Dim i As Integer = 1
For Each m As Match In matches
'Debug.Print(" match #" & i & ": " & m.Groups(1).Value)
i += 1
Next
Return matches.Count
End Function