How can I get only the first line of multiline text using regular expressions?
string test = @"just take this first line
even there is
some more
lines here";
Match m = Regex.Match(test, "^", RegexOptions.Multiline);
if (m.Success)
Console.Write(m.Groups[0].Value);
.is often touted to match any character, while this isn’t totally true..matches any character only if you use theRegexOptions.Singlelineoption. Without this option, it matches any character except for'\n'(end of line).That said, a better option is likely to be:And better yet, is Brian Rasmussen’s version: