boost::regex与不区分大小写的UTF-8匹配(例如大写字母与小写字母)
boost::regex with case-insensitive match with UTF-8 (e.g. uppercase versus lowercase umlauts)
在构建支持Unicode国际组件(ICU)的boost::regex 1.52版本库后,具有不区分大小写匹配的正则表达式似乎不能像预期的那样处理大写和小写的德国变音符。
static const std::string pattern("^.*" "303226" ".*$");
static const std::string test1("SCH" "303226" "NE");
static const std::string test2("sch" "303266" "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
使用Unicode和ICU字符串类型。
LWS示例。
#include <iostream>
#include <boost/regex.hpp>
#include <boost/regex/icu.hpp>
int main()
{
static const std::string pattern("^.*" "303226" ".*$");
static const std::string test1("SCH" "303226" "NE");
static const std::string test2("sch" "303266" "ne");
static const boost::u32regex exp=boost::make_u32regex(pattern, boost::regex::icase);
const char *result = (boost::u32regex_match(test1, exp)) ? "Match" : "NoMatch";
std::cout << "Testing "" << test1 << "" against pattern "" << pattern
<< "" : " << result << std::endl;
result = (boost::u32regex_match(test2, exp)) ? "Match" : "NoMatch";
std::cout << "Testing "" << test2 << "" against pattern "" << pattern
<< "" : " << result << std::endl;
}
相关文章:
- 如何在 c++ 中将所有大写字母转换为字符串中的小写字母,反之亦然?
- 大写字母
- 字符数组[]中的小写大写字母C++通过指针
- 如何在德语大写字母 Ä, Ö, Ü, ẞ 上正确应用 C++
- 删除 C 字符串中的大写字母
- 如何检查包含 utf8 文本的 std::string 在 Windows 中是否以大写字母开头?
- 正则表达式表示非连续大写字母和小写字母
- C++函数来检查 char 是否是大写字母,并且不计算给定字符串中的大写字母
- 将大写字母(从 cin 读取)更改为小写
- 如何验证小写和大写字母
- opencv :无法通过等待键读取大写字母
- 降低字符串字符,并在转换的大写字母前添加一个_
- 接收字符串,检查大写字母
- 如何计算字符串中大写字母、小写字母和数字的数量
- 如何在c++中用大写字母打印地址(十六进制值)
- Python:获取两个大写字母之间的字符串
- 使用std::sort对字符串进行排序,使大写字母位于小写字母之后
- 我的 cipher() 函数似乎不支持大写字母
- 在递归函数中计算大写字母
- 使用预处理器的大写字母C++ (x -> getX/setX)