TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to C-SHARP

C# RegexOptions.IgnoreCase Example

Use the Regex.IsMatch method with RegexOptions.IgnoreCase to ignore character cases.
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
Example. 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 using System; using System.Text.RegularExpressions; class Program { 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)); Console.WriteLine(Regex.IsMatch(value, "carrot")); } } Output True False
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.
Summary. 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.

© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf