I want to be able to match an entire line (hence word boundaries) with the pattern "ABC" ("ABC" is just used for convenience, I don’t want to check equality with a fixed line), so new lines are important to me. However, it turns out that a single "\ n", when placed at the end of a line, is ignored. Is there something wrong with my template?
Regex r = new Regex(@"^ABC$");
string[] strings =
{
"ABC",
"ABC\n",
"ABC\n\n",
"\nABC",
"ABC\r",
"ABC\r\n",
"ABC\n\r"
};
foreach(string s in strings)
{
Console.WriteLine(r.IsMatch(s));
}
source
share