Why doesn’t $ in .NET multiline regular expressions match CRLF?

From MSDN:

By default, $ matches only the end of the input string. If you specify the RegexOptions.Multiline option, it matches either the newline character (\n) or the end of the input string. It does not, however, match the carriage return/line feed character combination. To successfully match them, use the subexpression \r?$ instead of just $.

http://msdn.microsoft.com/en-us/library/yd1hzczs.aspx#Multiline

So I can’t say why (compatibility with regular expressions from other languages?), but at the very least it’s intended.

Leave a Comment