[英]Regex isMatch for cache pattern key
我为缓存扩展编写了测试。 我想通过模式从缓存中删除。
a)在此示例中,测试失败
[Test]
public void Should_found_by_pattern()
{
string pattern = "shouldFoundThis-{0}-{1}-{2}";
var regex = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase);
var keysToRemove = new List<String>();
var list = new List<string>()
{
"shouldFoundThis-15-2-7"
};
foreach (var item in list)
if (regex.IsMatch(item))
keysToRemove.Add(item);
keysToRemove.Any().ShouldBeTrue();
}
b)在此示例中,测试通过
[Test]
public void Should_found_by_pattern()
{
string pattern = "shouldFoundThis-{0}-{1}";
var regex = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase);
var keysToRemove = new List<String>();
var list = new List<string>()
{
"shouldFoundThis-15-2"
};
foreach (var item in list)
if (regex.IsMatch(item))
keysToRemove.Add(item);
keysToRemove.Any().ShouldBeTrue();
}
为什么Regex IsMatch与模式“shouldFoundThis- {0} - {1} - {3}”不匹配,但匹配模式“shouldFoundThis- {0} - {1}”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.