What I tried and failed...
match.Success is always wrong:
Regex pattern = new Regex(@"^-*Text\\r\\n");
sample text:
"--My Text" newline+return bla
What I tried and failed...
match.Success is always wrong:
Regex pattern = new Regex(@"^-*Text\\r\\n");
sample text:
"--My Text" newline+return bla
There's whitespace after the second "
in the sample text. Try inserting a space after the second "
in your pattern. Also, your question looks a lot like this one:
Technically, not all new lines will be a full \r\n - it's OS dependent. So you might want to adjust for that. However, assuming that the only environment you need to worry about is your own, and \r\n fits for that, then the following should do the trick (if I understand what you're looking for):
Regex pattern = new Regex(@"^-.*Text\r\n");
This is stating the following:
1. Line must start with one -
character
2. After the -
character, anything can come (including more -
characters) as long as it stays on the same line and is followed by the string Text
and then followed by \r\n
If you don't mean to require the string to be Text
, then it can be even simpler. The follow accepts anything as long as it starts with a -
and ends with a new line:
Regex pattern = new Regex(@"^-.*\r\n");