Why does ^.*$
does not match a line in:
This is some sample text
this is another line
this is the third line
how can I create a regular expression that will match an entire line so that when finding the next match it will return me the next line.
In other words I will like to have a regex so that the first match = This is some sample text
, next match = this is another line
etc...
^ and $ match on the entire input sequence. You need to use the Multiline Regex option to match individual lines within the text.
Regex rgMatchLines = new Regex ( @"^.*$", RegexOptions.Multiline);
See here for an explanation of the regex options. Here's what it says about the Multiline option:
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.
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