Hi.
I wanted to ask why .NET regex doesn't treat \n as end of line character? Sample code:
string[] words = new string[] { "ab1", "ab2\n", "ab3\n\n", "ab4\r", "ab5\r\n", "ab6\n\r" };
Regex regex = new Regex("^[a-z0-9]+$");
foreach (var word in words)
{
Console.WriteLine("{0} - {1}", word, regex.IsMatch(word));
}
And this is the response I get:
ab1 - True
ab2
- True
ab3
- False
- False
ab5
- False
ab6
- False
I don't understand why the regex matches ab2\n?
Update: I don't think MultiLine is a good solution, i.e. I want to validate login to match only specified characters and it must be single line. If I change the constructor for MultiLine option ab1, ab2, ab3 and ab6 match the expression, ab4 and ab5 don't match it.
Thanks in advance for help.