【问题标题】:std::regex_search override with parameter of range doesn't compile [duplicate]使用范围参数覆盖的 std::regex_search 无法编译 [重复]
【发布时间】:2020-10-13 03:20:36
【问题描述】:

我想使用 std::regex_search 的覆盖,它可以分配目标字符串的偏移量(范围)。

template< class BidirIt,
          class CharT, class Traits >
bool regex_search( BidirIt first, BidirIt last,
                   const std::basic_regex<CharT,Traits>& e,
                   std::regex_constants::match_flag_type flags = 
                       std::regex_constants::match_default );

以下是我无法编译的代码。去掉 m 参数可以让它工作,但我可以这样检索匹配信息。

string s = "a**b cd e*f.";
size_t asteriskPos = s.find('*');
std::smatch m;
bool b = std::regex_search(s.begin()+asteriskPos , s.end(), m, std::regex("[^a-z*]"));
cout << b << endl;

【问题讨论】:

    标签: c++ regex c++11 std


    【解决方案1】:

    我找到了这个C++: Why I can't pass a pair of iterators to regex_search?

    auto iter = test.cbegin();
    auto end = test.cend();
    

    常量迭代器可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-03
      • 2018-07-20
      • 1970-01-01
      • 2019-02-18
      • 1970-01-01
      • 2023-03-15
      • 2022-11-04
      • 1970-01-01
      相关资源
      最近更新 更多