Home > DeveloperSection > Forums > Regex.IsMatch clarification using C#
Andrew Deniel
Andrew Deniel

Total Post:29

Points:203
Posted on    October-14-2013 7:43 AM

 C# C# 
Ratings:


 1 Reply(s)
 1319  View(s)
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?



lois waisbrooker
lois waisbrooker

Total Post:70

Points:494
Posted on    October-14-2013 7:55 AM

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

Don't want to miss updates? Please click the below button!

Follow MindStick