Reputation: 4349
I am using Visual Studio 2010. This...
std::regex pattern("(?i).*a.*");
...throws this...
std::tr1::regex_error - regular expression error
...and I can't find anything that says if std::regex
supports the (?i)
syntax for case insensitivity or not.
Can anyone confirm/deny that (?i)
is not supported as a prefix for case insensitivity by std::regex
?
Upvotes: 29
Views: 14275
Reputation: 25657
The standard only requires conformance to the POSIX regular expression syntax (which does not include Perl extensions like this one) and conformance to the ECMAScript regular expression specification (with minor exceptions, per ISO 14882-2011§28.13), which is described in ECMA-262, §15.10.2. ECMAScript's regular expression grammar does not include the use of modifiers in the form of the (?)
syntax, so, by extension, neither does C++11/14, nor do most implementations of TR1.
That does not preclude your standard library from implementing more PCRE extensions, but the standard does not require it, so it's simply not guaranteed.
So, no, it's not supported, per se.
You can, however declare your regular expression as follows:
std::regex pattern(".*a.*", std::regex_constants::icase);
This will declare your pattern to be case-insensitive.
Upvotes: 53