REGEX.ISMATCH CLARIFICATION USING C#

Andrew Deniel

Total Post:29

Points:203
Posted by  Andrew Deniel
C# 
C#
 1814  View(s)
Ratings:
Rate this:

The following program does not find a match, I was expecting it to:

class Program
{
    static void Main(string[] args)
    {
        if (Regex.IsMatch("t1", "\bt1\b"))
        {
            return;  // I was expecting this to be hit but it is not
        }
    }
}

Can anyone point out what I have done wrong?

  1. lois waisbrooker

    Post:70

    Points:494
    Re: Regex.IsMatch clarification using C#

    You need to escape \b


    Use \\ to escape it or just use @ verbatim.


    if (Regex.IsMatch("t1", @"\bt1\b"))

    {

        return;  //This works as expected

    }

      Modified On Oct-16-2013 10:11:26 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!