Regex pattern failing
- by Scott Chamberlain
I am trying a substring to find from the beginning of the string to the point that has the escape sequence "\r\n\r\n" my regex is Regex completeCall = new Regex(@"^.+?\r\n\r\n", RegexOptions.Compiled); it works great as long as you only have strings like 123\r\n\r\n however once you have the pattern 123\r\n 456\r\n\r\n the pattern no longer matches.
Any advice on what I am doing wrong?
Regex completeCall = new Regex(@"^.+?\r\n\r\n", RegexOptions.Compiled);
Regex junkLine = new Regex(@"^\D", RegexOptions.Compiled);
private void ClientThread()
{
StringBuilder stringBuffer = new StringBuilder();
(...)
while(true)
{
(...)
Match match = completeCall.Match(stringBuffer.ToString());
while (Match.Success) //once stringBuffer has somthing like "123\r\n 456\r\n\r\n" Match.Success always returns false.
{
if (junkLine.IsMatch(match.Value))
{
(...)
}
else
{
(...)
}
stringBuffer.Remove(0, match.Length); // remove the processed string
match = completeCall.Match(stringBuffer.ToString()); // check to see if more than 1 call happened while the thread was sleeping.
}
Thread.Sleep(1000);
}