C# RegEx: Ignore case... in pattern?
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))
(?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)
.