[英]C# regexoptions.ignorecase doesn't seem to work
Using the following code: 使用以下代码:
string pat = @"ENGL101_.*_(.*)";
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
Matches: ENGL101_BELIEVE_WRIGHTSTONE.docx 匹配项:ENGL101_BELIEVE_WRIGHTSTONE.docx
but not: Engl101_ThisIBelieve_Williams.docx 但不是:Engl101_ThisIBelieve_Williams.docx
IgnoreCase is on-- what's the issue?? IgnoreCase处于启用状态-问题是什么??
I can't replicate this problem; 我无法重复这个问题; both the strings appear to match the expression. 两个字符串似乎都与表达式匹配。
[STAThread]
static void Main()
{
string pat = @"ENGL101_.*_(.*)";
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
Console.WriteLine(r.IsMatch(@"ENGL101_BELIEVE_WRIGHTSTONE.docx"));
Console.WriteLine(r.IsMatch(@"Engl101_ThisIBelieve_Williams.docx"));
}
Output: 输出:
True
True
The problem must be something else, perhaps? 可能是其他问题了吗?
I know this may sound obvious, but have you tried matching against 我知道这听起来似乎很明显,但是您是否尝试过匹配
ENGl101_THISIBELIEVE_WILLIAMOS.docx ENGl101_THISIBELIEVE_WILLIAMOS.docx
without ignore case? 没有忽略的情况?
Can't repro - tried in Snippet Compiler and: 无法复制-在Snippet Compiler中尝试过:
public static void RunSnippet()
{
string pat = @"ENGL101_.*_(.*)";
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
Match m = r.Match("ENGL101_BELIEVE_WRIGHTSTONE.docx");
WL(m.Success);
m = r.Match("Engl101_ThisIBelieve_Williams.docx");
WL(m.Success);
}
Returns 返回
True
True
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.