C# RegEx: Ignore case... in pattern?

C#Regex

C# Problem Overview


I'm using System.Text.RegularExpressions.Regex.IsMatch(testString, regexPattern) to do some searches in strings.

Is there a way to specify in the regexPattern string that the pattern should ignore case? (I.e. without using Regex.IsMatch(testString, regexPattern, RegexOptions.IgnoreCase))

C# Solutions


Solution 1 - C#

(?i) within the pattern begins case-insensitive matching, (?-i) ends it. That is,

(?i)foo(?-i)bar

matches FOObar but not fooBAR.

EDIT: I should have said (?-i) starts case-sensitive matching - if you want the whole pattern to be case-insensitive then you don't need to "end" the (?i).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncoreView Question on Stackoverflow
Solution 1 - C#stevemegsonView Answer on Stackoverflow