0

I guess the answer should be obvious but I don't understand

Regex reg = new Regex("a\r\n", RegexOptions.Singleline | RegexOptions.CultureInvariant);
Console.WriteLine(reg.IsMatch(".*a.*")); // writes FALSE

Why does this write false ? I thought that SingleLine allowed the dot to match anything, be it \r, \n, \r\n, \n\r or whatever ?

1
  • 3
    I think you are backwards, the pattern should be in the constructor of the Regex you have what you want to match there. Commented Jun 13, 2013 at 14:37

1 Answer 1

3

You are backwards, you want to put the pattern in the constructor of the Regex rather than what you are trying to match. Try this:

Regex reg = new Regex(".*a.*", RegexOptions.Singleline | RegexOptions.CultureInvariant);
Console.WriteLine(reg.IsMatch("a\r\n")); // writes TRUE
Sign up to request clarification or add additional context in comments.

1 Comment

Omg I can't believe it ... that's what I would call forgetting the bigger picture. Thank you for pointing that out ! I'm going to check it again tomorrow

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.