Как вы уже узнали, (?i)
- это встроенный эквивалент RegexOptions.IgnoreCase
.
Просто к вашему сведению, есть несколько приемов, которые вы можете сделать с ним:
Regex:
a(?i)bc
Matches:
a # match the character 'a'
(?i) # enable case insensitive matching
b # match the character 'b' or 'B'
c # match the character 'c' or 'C'
Regex:
a(?i)b(?-i)c
Matches:
a # match the character 'a'
(?i) # enable case insensitive matching
b # match the character 'b' or 'B'
(?-i) # disable case insensitive matching
c # match the character 'c'
Regex:
a(?i:b)c
Matches:
a # match the character 'a'
(?i: # start non-capture group 1 and enable case insensitive matching
b # match the character 'b' or 'B'
) # end non-capture group 1
c # match the character 'c'
И вы даже можете комбинировать флаги следующим образом: a(?mi-s)bc
значение:
a # match the character 'a'
(?mi-s) # enable multi-line option, case insensitive matching and disable dot-all option
b # match the character 'b' or 'B'
c # match the character 'c' or 'C'