Regex.IsMatch clarification using C#

Total Post:29

Points:203

C# 
C#
 2444  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. 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

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.