I'm trying to highlight markdown code, but am running into this weird behavior of the .NET regex multiline option.
The following expression:
RegExpression = new Regex(@"^(#+).+$", RegexOptions.Multiline)
It is clear your text contains a linebreak other than LF. In .NET regex, a dot matches any char but LF. So, use
.+?\r?$ will match lazily any one or more chars other than LF up to the first CR (that is optional) right before a newline.
Or just use a negated character class:
[^\r\n]+ will match one or more chars other than CR/LF.