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
?
Case-Sensitive Match To disable case-sensitive matching for regexp , use the 'ignorecase' option.
By default, the comparison of an input string with any literal characters in a regular expression pattern is case-sensitive, white space in a regular expression pattern is interpreted as literal white-space characters, and capturing groups in a regular expression are named implicitly as well as explicitly.
Discussion. Currently, REGEXP is not case sensitive, either.
The Regex type in the C# language by default is case-sensitive. But RegexOptions. IgnoreCase, an enum value, relaxes this. Example.
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.
boost::regex supports Perl syntax, which has (?i)
.
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