How would a regex pattern to match each line of a given text be?
I'm trying ^(.+)$
but it includes crlf...
Just use RegexOptions.Multiline.
Multiline mode. Changes the meaning of ^ and $ so they match at the beginning and end, respectively, of any line, and not just the beginning and end of the entire string.
Example:
var lineMatches = Regex.Matches("Multi\r\nlines", "^(.+)$", RegexOptions.Multiline);
I'm not sure what you mean by "match each line of a given text" means, but you can use a character class to exclude the CR and LF characters:
[^\r\n]+
The wording of your question seems a little unclear, but it sounds like you want RegexOptions.Multiline
(in the System.Text.RegularExpressions
namespace). It's an option you have to set on your RegEx object. That should make ^
and $
match the beginning and end of a line rather than the entire string.
For example:
Regex re = new Regex("^(.+)$", RegexOptions.Compiled | RegexOptions.Multiline);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With