I have a string like this:
N:string of unknown length\r\n
I want “string of unknown length” read into a variable.
N: is always the start of the string, and \r\n is always the end of the string, and i need all in between.
My c#
String pattern ="help needed"
string result = Regex.IsMatch(pattern,myString).ToString();
EDIT!!
Sorry but I have found that I was very unclear about what I wanted.
The string I am looking for N:string of unknown length\r\n is a substring of a larger string.
Fx Bla bla\r\n bla bla N:string of unknown length\r\n more bla bla N:string of unknown length\r\n
And it will occur only once.
If it always starts with “N:” and always ends with “\r\n” then you don’t need regular expressions at all – you can just use Substring:
(That’s assuming that by “\r\n” you actually mean the two individual characters ‘\r’ and ‘\n’. If you mean four characters, change the 4 to 6.)
If you want to do validation as well, I’d use: