I need find text lower case or upper case (using regex) My code:
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());
}
}
It result :
hello
I need result
hello
Hello
HELLO
hEllo
Can you help me?
Two ways:
String patern = @"(?i)(hello)";
(?i) turns on case-insensitive comparison, and (?-i) restores the default case-sensitive comparison.
Or use the RegexOptions.IgnoreCase
option when creating your regex object:
Regex myRegex = new Regex(patern, RegexOptions.IgnoreCase);
尝试这个
String patern = @"[Hh][Ee][Ll][Ll][Oo]";
Pass RegexOptions.IgnoreCase when searching.
http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regexoptions.aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.