我需要查找文本小写或大写(使用正则表达式)我的代码:
static void Main(string[] args)
{
String s = "String : hello Hello HELLO hEllo ";
String patern = @"(hello)";
Regex myRegex = new Regex(patern);
foreach (Match regex in myRegex.Matches(s)) {
Console.WriteLine(regex.Value.ToString());
}
}
其结果是:
hello
我需要结果
hello
Hello
HELLO
hEllo
你能帮帮我吗?
发布于 2013-06-26 02:53:59
两种方式:
String patern = @"(?i)(hello)";
(?i)打开不区分大小写的比较,(?-i)恢复默认的区分大小写的比较。
或者在创建正则表达式对象时使用RegexOptions.IgnoreCase
选项:
Regex myRegex = new Regex(patern, RegexOptions.IgnoreCase);
发布于 2013-06-26 02:50:26
尝尝这个
String patern = @"[Hh][Ee][Ll][Ll][Oo]";
发布于 2013-06-26 02:53:58
搜索时传入RegexOptions.IgnoreCase。
http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regexoptions.aspx
https://stackoverflow.com/questions/17310737
复制相似问题