2010-12-06 107 views
7

这是我的尝试:boost :: regex_search可以在wstring上完成吗?

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; 
    } 
+3

当你尝试它时发生了什么? – aschepler 2010-12-06 22:16:58

+0

错误C2784:'bool boost :: regex_search(const std :: basic_string &,const boost :: basic_regex &,boost :: regex_constants :: match_flag_type)':无法推导'const boost模板参数:: basic_regex &'from'boost :: smatch' – coolface 2010-12-06 22:22:23

+0

我相信当你使用`std :: wstring`时,你必须使用boost.regex的'w'形式,如`boost :: wregex`和`boost :: wsmatch`。另外,如果您在进行Unicode匹配,请查看以下链接:http://www.boost.org/doc/libs/1_45_0/libs/regex/doc/html/boost_regex/unicode.html – birryree 2010-12-06 22:24:56

回答

14

使用wregex和wsmatch

2

我相信是这样,但你需要使用boost::wsmatch代替smatch,并wregex为好。