Is gcc 4.8 or earlier buggy about regular expressions?

前端 未结 3 1792
一向
一向 2020-11-21 04:29

I am trying to use std::regex in a C++11 piece of code, but it appears that the support is a bit buggy. An example:

#include 
#include 

        
3条回答
  •  悲哀的现实
    2020-11-21 04:59

    At this moment (using std=c++14 in g++ (GCC) 4.9.2) is still not accepting regex_match.

    Here is an approach that works like regex_match but using sregex_token_iterator instead. And it works with g++.

    string line="1a2b3c";
    std::regex re("(\\d)");
    std::vector inVector{
        std::sregex_token_iterator(line.begin(), line.end(), re, 1), {}
    };
    
    //prints all matches
    for(int i=0; i

    it will print 1 2 3

    you may read the sregex_token_iterator reference in: http://en.cppreference.com/w/cpp/regex/regex_token_iterator

提交回复
热议问题