jeudi 30 août 2018

C++ regex library

I have this sample code

// regex_search example
#include <iostream>
#include <string>
#include <regex>

int main ()
{
  std::string s ("eritueriotu3498 \"pi656\" sdfs3646df");
  std::smatch m;
  std::string reg("\\(?<=pi\\)\\(\\d+\\)\\(?=\"\\)");
  std::regex e (reg);   

  std::cout << "Target sequence: " << s << std::endl;

  std::cout << "The following matches and submatches were found:" << std::endl;

  while (std::regex_search (s,m,e)) {
     for (auto x:m) std::cout << x << " ";
     std::cout << std::endl;
     s = m.suffix().str();
  }

  return 0;
}

I need to get number between pi and " -> (piMYNUMBER") In online regex service my regex works fine (?<=pi)(\d+)(?=") but c++ regex don't match anything.

Who knows what is wrong with my expression? Best regards

Aucun commentaire:

Enregistrer un commentaire