C# RegexOptions.IgnoreCase ExampleThis C# program uses the Regex.IsMatch method with RegexOptions.IgnoreCase.
Sometimes text data has inconsistent casing. Some data is uppercase, and some lowercase, but both are valid. The Regex type in the C# language by default is case-sensitive. RegexOptions.IgnoreCase relaxes this.Regex
The RegexOptions enum is typically passed as the last argument to a Regex method. This example shows how RegexOptions.IgnoreCase affects the result of the IsMatch method on an input that is in a different case.
Note: When IgnoreCase is specified, the match succeeds. Otherwise it fails. IgnoreCase will relax the regular expression.
C# program that uses RegexOptions.IgnoreCase constant
static void Main()
// The input string has an uppercase trailing letter.
const string value = "carroT";
// Print result of IsMatch method:
// ... With IgnoreCase;
// ... And without any options set.
Console.WriteLine(Regex.IsMatch(value, "carrot", RegexOptions.IgnoreCase));
Other methods. You can use RegexOptions.IgnoreCase with other methods, not just IsMatch. Try it with Split, Matches and Match. It has the same effect when used with these methods.
The RegexOptions.IgnoreCase enumerated constant is simple in its intent and also its application. It will relax the requirements for an input with letters to be matched. Thus, the input string can have a capital or lowercase letter.
Tip: The RegexOptions.IgnoreCase argument is useful in many regular expressions.
© 2007-2019 Sam Allen. Every person is special and unique. Send bug reports to firstname.lastname@example.org.