I'm having trouble understanding the reason for the output of the following code
public static void Main()
{
var p1 = "txtbox";
CheckMatch(p1);
p1 = "txtbox_asd";
CheckMatch(p1);
p1 = "txtbox_asdf";
CheckMatch(p1);
p1 = "txtbox_asd2";
CheckMatch(p1);
}
public static void CheckMatch(string p1)
{
var reg = new Regex(@"txtbox");
if (!reg .IsMatch(p1))
{
Console.WriteLine($"{p1} doesn't match");
}
else
{
Console.WriteLine($"{p1} matches");
}
}
All of the cases are returning 'matches', whereas I am only expecting the first case to match. Is there a way to have it s.t. only the first case matches?