G
Guest
I'm trying to do some regex in C# but for some reason linebreaks are causing
my regex to not work.
the test string goes like this:
string ss = "<tagname
something=45678&somethingelse=12345>blah</tagname>\r\n<tag2>stuff</tag2>";
and my regex code is like:
Regex pat = new Regex("something=([0-9]*).*>(.*)<.*<tag2>(.*)</tag2>",
RegexOptions.Multiline);
foreach (Match m in pat.Matches(ss)) {
foreach (Group g in m.Groups) {
Console.Write(g+", ");
}
Console.WriteLine();
}
but it never works unless I remove the "\r\n" from the test string.
how do I get around that? I thought that's what the RegexOptions.Multiline
was supposed to take care of?
my regex to not work.
the test string goes like this:
string ss = "<tagname
something=45678&somethingelse=12345>blah</tagname>\r\n<tag2>stuff</tag2>";
and my regex code is like:
Regex pat = new Regex("something=([0-9]*).*>(.*)<.*<tag2>(.*)</tag2>",
RegexOptions.Multiline);
foreach (Match m in pat.Matches(ss)) {
foreach (Group g in m.Groups) {
Console.Write(g+", ");
}
Console.WriteLine();
}
but it never works unless I remove the "\r\n" from the test string.
how do I get around that? I thought that's what the RegexOptions.Multiline
was supposed to take care of?