Reputation: 13
Regex has set option IgnoreCase. Is it possible to turn off case insensitivity using pattern only (like negation of (?i))?
In example below, find pattern for which result would be "aBaaaBBaaB".
string pattern = "???";
string input = "aAaaaAAaaA";
var regex = new Regex(pattern, RegexOptions.IgnoreCase);
var result = regex.Replace(input, "B");
Upvotes: 0
Views: 35
Reputation: 239814
You can turn off options inline by using -
before the option. E.g. the negation of (?i)
is (?-i)
:
a minus sign (-) before an option or set of options turns those options off. For example, (?i-mn) turns case-insensitive matching (i) on, turns multiline mode (m) off, and turns unnamed group captures (n) off.
Upvotes: 1