【问题标题】:Ignore case using boost::regex_search使用 boost::regex_search 忽略大小写
【发布时间】:2011-09-09 01:11:32
【问题描述】:

如何在 C++ 中将 boost::regex_search 与忽略大小写标志或常量一起使用?

请发布一个简单的例子。

谢谢!

【问题讨论】:

    标签: c++ boost-regex ignore-case


    【解决方案1】:

    或者类似的东西(不设置boost::regex::icase):

    boost::regex regex("(?i)expression");
    boost::smatch what;
    
    string mystring;
    bool search_result = boost::regex_search(mystring.begin(),mystring.end(), what, regex);
    

    【讨论】:

      【解决方案2】:

      你需要这样的东西

      boost::regex regex("your expression here", boost::regex::icase);
      boost::smatch what;
      
      string mystring;
      bool search_result = boost::regex_search(mystring.begin(),mystring.end(), what, regex);
      

      【讨论】:

      • 如果不需要,可以省略“what”参数(匹配结果),并且可以传递字符串本身而不是其迭代器。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多