I think you're looking for the RegexOptions.Multiline option. As in:
Regex myEx = new Regex("^[A-Z0-9,]+\".+?\"$", RegexOptions.Multiline);
Actually, the regular expression should be:
"^[A-Z0-9,]+\".*\"\r?$"
Multiline
looks for the newline character, \n
. But the file contains \r\n
. So it finds the ending quote, sees the $
, and looks for the newline. But the file has Windows line endings (\r\n
). My modified regex skips over that character if it's there.
If you want to eliminate those characters in your results, make a capture group:
"^([A-Z0-9,]+\".*\")\r?$"
Or, you can filter them by calling Trim
on each result:
MatchCollection matches = myEx.Matches(text);
foreach (Match m in matches)
{
string s = m.Value.Trim(); // removes trailing \r
}