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

I am using System.Text.RegularExpressions.Regex.IsMatch (testString, regexPattern) to do some string searches.

Is there a way to indicate on the regexPattern line that the template should ignore case? (Ie without using Regex.IsMatch (testString, regexPattern, RegexOptions.IgnoreCase))

+49
c # regex
Oct 18 '09 at 1:14
source share
1 answer

(?i) inside the pattern, case-insensitive matching begins, (?-i) completes it. I.e

 (?i)foo(?-i)bar 

corresponds to FOObar , but not FOObar .

EDIT: I had to say that (?-i) triggers a case-sensitive match - if you want the whole pattern to be case-insensitive, then you don't need to “complete” (?i) .

+102
Oct 18 '09 at 1:27
source share



All Articles