MSVC 2008 tr1::regex ignores icase flag?

A

Arnold Smit

Group,

MSVC 2008 seems to have a bug in their tr1::regex<> class.
The following code gives: true & false

#include <regex>
#include <iostream>
using namespace std;
int main()
{
tr1::basic_regex<char> regex("[A-Z]+", tr1::regex::ECMAScript | tr1::regex::icase);
cout<< std::boolalpha << tr1::regex_match("MATCH", regex) << endl; // gives true
cout<< std::boolalpha << tr1::regex_match("MaTcH", regex) << endl; // gives false ?
}

Shouldn't the flag tr1::regex::icase cause the regex to be case insensitive?
Is there a way to accomplish 'ignore case' in the shipped msvc 2008 tr1::regex class,
or should i start looking into boost::regex?

Regards Arnold
 
B

Balog Pal

Arnold Smit said:
#include <regex>
#include <iostream>
using namespace std;
int main()
{
tr1::basic_regex<char> regex("[A-Z]+", tr1::regex::ECMAScript |
tr1::regex::icase);
cout<< std::boolalpha << tr1::regex_match("MATCH", regex) << endl; //
gives true
cout<< std::boolalpha << tr1::regex_match("MaTcH", regex) << endl; //
gives false ?
}

Shouldn't the flag tr1::regex::icase cause the regex to be case
insensitive?
Is there a way to accomplish 'ignore case' in the shipped msvc 2008
tr1::regex class,
or should i start looking into boost::regex?

Does enum having icase defined an operator |?
If not your ctor calls an unintended overload, where 2nd param is size_t
len, and the third picks up default flags = ECMAScript...). Try to cast the
second arg to flag_type or whatever.
 
B

Balog Pal

Balog Pal said:
Arnold Smit said:
#include <regex>
#include <iostream>
using namespace std;
int main()
{
tr1::basic_regex<char> regex("[A-Z]+", tr1::regex::ECMAScript |
tr1::regex::icase);
cout<< std::boolalpha << tr1::regex_match("MATCH", regex) << endl; //
gives true
cout<< std::boolalpha << tr1::regex_match("MaTcH", regex) << endl; //
gives false ?
}

Shouldn't the flag tr1::regex::icase cause the regex to be case
insensitive?
Is there a way to accomplish 'ignore case' in the shipped msvc 2008
tr1::regex class,
or should i start looking into boost::regex?

Does enum having icase defined an operator |?

Yes it has.
If not your ctor calls an unintended overload, where 2nd param is size_t
len, and the third picks up default flags = ECMAScript...). Try to cast
the second arg to flag_type or whatever.

This is not the problem for the case. (though one can be hit by it creating
the bitmask in a separate variable that is int or like...)

As I read the msdn page
http://msdn.microsoft.com/en-us/library/bb982727.aspx#formatflags
IUC the case-insensitive comparision modifier only applies to "ordinary"
characters, not [] sets.

Reading the part of standard implies similar, icase is mentioned matching
char to char, and matching against a character class, not in the bullet with
range.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top