【问题标题】:Can boost::regex_search be done on a wstring?boost::regex_search 可以在 wstring 上完成吗?
【发布时间】:2010-12-06 22:15:10
【问题描述】:

这是我尝试过的:

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

【问题讨论】:

  • 当你尝试它时发生了什么?
  • 错误 C2784: 'bool boost::regex_search(const std::basic_string &,const boost::basic_regex &,boost::regex_constants:: match_flag_type)' : 无法从 'boost::smatch' 中推断出 'const boost::basic_regex &' 的模板参数
  • 我相信当你使用std::wstring时,你将不得不使用boost.regex的'w'形式,比如boost::wregexboost::wsmatch。此外,如果您进行 Unicode 匹配,请查看此链接:boost.org/doc/libs/1_45_0/libs/regex/doc/html/boost_regex/…

标签: c++ regex boost


【解决方案1】:

使用 wregex 和 wsmatch

【讨论】:

    【解决方案2】:

    我相信是这样,但您需要使用boost::wsmatch 而不是smatch,以及wregex

    【讨论】:

    • 错误 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 &' 的模板参数
    猜你喜欢
    • 2011-06-20
    • 1970-01-01
    • 1970-01-01
    • 2015-11-13
    • 1970-01-01
    • 1970-01-01
    • 2011-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多