C++ 如何使用正则表达式将字符串仅与中文字母匹配?
我想得到一个正则表达式,它只能匹配一个由汉字组成的字符串,而不能匹配英语或任何其他字符。[\u4e00-\u9fa5]根本不起作用,[^x00 xff]将使用标点符号或其他语言字符匹配情况C++ 如何使用正则表达式将字符串仅与中文字母匹配?,c++,regex,visual-c++,boost,unicode,C++,Regex,Visual C++,Boost,Unicode,我想得到一个正则表达式,它只能匹配一个由汉字组成的字符串,而不能匹配英语或任何其他字符。[\u4e00-\u9fa5]根本不起作用,[^x00 xff]将使用标点符号或其他语言字符匹配情况 boost::wregex reg(L"\\w*"); bool b = boost::regex_match(L"我a", reg); // expected to be false b = boost::regex_match(L"我,", reg); // expected to
boost::wregex reg(L"\\w*");
bool b = boost::regex_match(L"我a", reg); // expected to be false
b = boost::regex_match(L"我,", reg); // expected to be false
b = boost::regex_match(L"我", reg); // expected to be true
与重症监护室合作。我想你在找
\p{Han}
脚本。或者,U+4E00..U+9FFF是\p{InCJK\U Unified\U Ideographs}
以下正则表达式工作正常
boost::wregex reg(L"^[\u4e00-\u9fa5]+");
@尼古拉斯:问题是关于
boost::regex
,而不是关于C++11std::regex
@MSalters:足够公平了。