lundi 2 août 2021

Why the regex to mark beginning of line doesn't work?

Why the commented regex doesn't work? I thought '^' also marks beginning of line. isn't it?

#include <iostream>
#include <regex>

int main()
{
     std::string str ("this subject has a submarine as a subsequence");
     std::regex re ("\\b(sub)([^ ]*)");
     // std::regex re ("^(sub)([^ ]*)");
     // std::regex re ("(^sub)([^ ]*)");
     
      std::cout << "entire matches:"; 
      std::regex_token_iterator<std::string::iterator> rend;
      std::regex_token_iterator<std::string::iterator> a ( str.begin(), str.end(), re );
      while (a!=rend) std::cout << " [" << *a++ << "]";
      std::cout << std::endl;
  
      return 0;
}

Aucun commentaire:

Enregistrer un commentaire