In our code there is a regular expression of the following form:
string regex = @"(?i)foo=(BAR?-[A-Z]+(33|34)?)";
What does the "(?i)
" at the beginning of the regex match/do? I've looked through the .NET regex documentation and can't seem to figure out what (?i)
would mean. Thanks!
(?i)
activates case-insensitive matching.
Reference: MSDN, Regular Expression Options (highlighting by me):
You can specify options for regular expressions in one of three ways:
In the options parameter of a
System.Text.RegularExpressions.Regex
class constructor or static (Shared in Visual Basic) pattern-matching method, such asRegex.Regex(String, RegexOptions)
orRegex.Match(String, String, RegexOptions)
. [...]By applying inline options in a regular expression pattern with the syntax (?imnsx-imnsx). The option applies to the pattern from the point that the option is defined to either the end of the pattern or to the point at which the option is undefined by another inline option. [...]
By applying inline options in a particular grouping construct in a regular expression pattern with the syntax (?imnsx-imnsx:subexpression). [...]
(?i)
means: Ignore case option enabled.
It's equivalent to call Regex.Matches
with 3rd param RegexOptions.IgnoreCase
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With