I have an extension method like this;
public static bool IsBoolean(this string value)
{
string lower = value.ToLower(CultureInfo.InvariantCulture);
return new Regex("[true]|[false]|[0]|[1]", RegexOptions.Compiled).IsMatch(lower);
}
But this regex pattern fails when I give "fals" or "tru" as value. Such as;
[Theory(DisplayName = "IsBoolean")]
[InlineData("FALS")]
[InlineData("Fals")]
[InlineData("TRU")]
[InlineData("Tru")]
public void IsNotBoolean(string value)
{
bool result = value.IsBoolean();
Assert.False(result);
}
All these tests has been failed. Because result is true.
How is this possible? Is this regex pattern wrong ?