It is clear your text contains a linebreak other than LF. In .NET regex, a dot matches any char but LF (a newline char,
).
See Multiline Mode MSDN regex reference
By default, $
matches only the end of the input string. If you specify the RegexOptions.Multiline option, it matches either the newline character (
) 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
?$
instead of just $
.
So, use
@"^(#+).+?
?$"
The .+?
?$
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:
@"^(#+)[^
]+"
The [^
]+
will match one or more chars other than CR/LF.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…