在使用支持 Unicode (ICU) 的国际组件构建 boost::regex 版本 1.52 库后,具有不区分大小写匹配的正则表达式似乎无法按预期处理大写和小写的德语变音符号字符。
static const std::string pattern("^.*" "\303\226" ".*$");
static const std::string test1("SCH" "\303\226" "NE");
static const std::string test2("sch" "\303\266" "ne");
static const boost::regex exp(pattern, boost::regex::icase);
const char *result = (boost::regex_match(test1, exp)) ? "Match" : "NoMatch";
std::cout << "Testing \"" << test1 << "\" against pattern \"" << pattern
<< "\" : " << result << std::endl;
result = (boost::regex_match(test2, exp)) ? "Match" : "NoMatch";
std::cout << "Testing \"" << test2 << "\" against pattern \"" << pattern
<< "\" : " << result << std::endl;
产量:
Testing "SCHÖNE" against pattern "^.*Ö.*$" : Match
Testing "schöne" against pattern "^.*Ö.*$" : NoMatch