Regex pattern failing

Posted by Scott Chamberlain on Stack Overflow See other posts from Stack Overflow or by Scott Chamberlain
Published on 2010-04-28T14:10:21Z Indexed on 2010/04/28 14:13 UTC
Read the original article Hit count: 486

Filed under:
|

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);
    }

© Stack Overflow or respective owner

Related posts about regex

Related posts about c#