fork download
  1. #include <iostream>
  2. #include <iterator>
  3. #include <string>
  4. #include <regex>
  5.  
  6. void test(std::string const& data)
  7. {
  8. std::cout << "Input string: " << data << std::endl;
  9.  
  10. std::regex reg("((pi|e|x|([-]?[0-9]*[.]?[0-9]+)){2,})");
  11. auto tokens_begin = std::sregex_iterator(data.begin(), data.end(), reg);
  12. auto tokens_end = std::sregex_iterator();
  13. for (std::sregex_iterator i = tokens_begin; i != tokens_end; ++i)
  14. {
  15. std::smatch match = *i;
  16. std::string match_str = match.str();
  17. std::cout << "Match: " << match_str << '\n';
  18. }
  19.  
  20. std::cout << std::endl;
  21. }
  22.  
  23. int main()
  24. {
  25. test("piex14.3");
  26. test("14e");
  27. test("12.5pi");
  28. test("ex");
  29. }
  30.  
Success #stdin #stdout 0s 4344KB
stdin
Standard input is empty
stdout
Input string: piex14.3
Match:  piex14.3

Input string: 14e
Match:  14e

Input string: 12.5pi
Match:  12.5pi

Input string: ex
Match:  ex