Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想答案应该很明显,但我不明白
Regex reg = new Regex("a\r\n", RegexOptions.Singleline | RegexOptions.CultureInvariant); Console.WriteLine(reg.IsMatch(".*a.*")); // writes FALSE
为什么这写 false ?我认为 SingleLine 允许点匹配任何东西,无论是 \r、\n、\r\n、\n\r 还是其他什么?
你倒退了,你想把模式放在构造函数中,Regex而不是你试图匹配的东西。尝试这个:
Regex
Regex reg = new Regex(".*a.*", RegexOptions.Singleline | RegexOptions.CultureInvariant); Console.WriteLine(reg.IsMatch("a\r\n")); // writes TRUE