Regex.IsMatch clarification using C#

Total Post:29

Points:203
C# 
C#
 2124  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. 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 Apr-03-2018 05:01:23 AM

Answer

NEWSLETTER

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