I have a function who gets a regular expression as parameter.
The function use the regular expression to check if the entire content of the file is matched (is a format checking). Then the function returns the matches.
An example of the text file is this key:value pair list:
1:
2:
3:some value.
4:other value
5:
6:
7:
8:
9:
10:another
The regular expression is this:
(?<Line>^(?<KeyNumber>\d+):(?<Value>[ ,\S]*(?:(?=\W$)|\z)))+
The modifiers (wich I cannot change), are:
RegexOptions.Compiled Or _
RegexOptions.CultureInvariant Or _
RegexOptions.ExplicitCapture Or _
RegexOptions.IgnoreCase Or _
RegexOptions.Multiline Or _
RegexOptions.Singleline
The group "Line" should return each line (10 in total), and it works in Expresso:
But for a reason I cannot understand, it don't work in VB.NET. I'm sure that I used the six modifiers posted above (multiline, culture invariant, etc)
This code only gets a single "line", instead of 10:
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim RegexString As String = "(?<Line>^(?<KeyNumber>\d+):(?<Value>[ ,\S]*(?:(?=\W$)|\z)))+"
Dim ExampleText As String = String.Join(vbCrLf, New String() {"1:", _
"2:", _
"3:Some Value ", _
"4:Other value", _
"5:", _
"6:", _
"7:", _
"8:", _
"9:", _
"10:Another"})
Dim MyParser As New Regex(RegexString, _
RegexOptions.Compiled Or _
RegexOptions.CultureInvariant Or _
RegexOptions.ExplicitCapture Or _
RegexOptions.IgnoreCase Or _
RegexOptions.Multiline Or _
RegexOptions.Singleline)
Dim Clases As Match = MyParser.Match(ExampleText)
MsgBox("Total number of ""Line"" captures: " & Clases.Groups("Line").Captures.Count)
End Sub
End Class
It makes nonsense. I can't understand why it don't works. Can you help me?