I am trying to use a regex in c# to parse a multi line file ( Currently just in a string ) And this part seems to be where the problem is (.*?\n) it will split the .v/L1 and .v/L2 however when I put a nl between it fails the input file will look something like this.
MSG
.v/1L
.v/2L
.some other data
.and so on
ENDMSG
And this is part of the c# code
string nl = new string(new char[] { '\u000A' });
string pattern = @"(?<group>((?<type>MSG\n)(.*?\n)(?<end>ENDMSG\n)))";
string input = @" MSG" + nl + ".v/1L.v/2L" + nl + "ENDMSG" + nl;
// The Line below doesn't work
//string input = @" MSG" +nl+ ".v/1L" +nl+ ".v/2L" +nl+ "ENDMSG" + nl;
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
And this is the output of the one that works:
Starting RegEx !
RegEx : (?<group>((?<type>MSG\n)(.*?\n)(?<end>ENDMSG\n)))
'MSG
.v/1L.v/2L << Should be split into 2 when adding a \n between
ENDMSG
' found at index 1.
Executing finally block.