C++ boost::regex_搜索可以在wstring上完成吗?
这就是我所尝试的:C++ boost::regex_搜索可以在wstring上完成吗?,c++,regex,boost,C++,Regex,Boost,这就是我所尝试的: std::wstring extractText(std::wstring line) { std::wstring text; boost::regex exp("^.*?PRIVMSG #.*? :(.+)"); boost::smatch match; if (boost::regex_search(line, match, exp)) { text = std::wstring(match[1].firs
std::wstring extractText(std::wstring line) {
std::wstring text;
boost::regex exp("^.*?PRIVMSG #.*? :(.+)");
boost::smatch match;
if (boost::regex_search(line, match, exp)) {
text = std::wstring(match[1].first, match[1].second);
}
return text;
}
我相信是这样,但是你需要使用
boost::wsmatch
而不是smatch
,还有wregex
。使用wregex和wsmatch以及你尝试它时发生了什么?错误C2784:'bool boost::regex_搜索(const std::basic_string&,const boost::basic_regex&,boost::regex常量::match_flag_类型)“:无法从“boost::smatch”中推断出“const boost::basic_regex&”的模板参数。我相信当您使用std::wstring
时,您必须使用boost.regex的“w”形式,如boost::wregex
和boost::wsmatch
。另外,如果您进行Unicode匹配,请查看以下链接:错误C2784:“bool boost::regex_search(const std::basic_string&,const boost::basic_regex&,boost::regex_constants::match_flag_type)”:无法从“boost::wsmatch”推断“const boost::basic_regex&”的模板参数