fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <regex>
  4.  
  5. int main()
  6. {
  7. std::string input = "+10.7% Is My String +5 And Some Extra Stuff Here";
  8. std::regex rx("\\+([0-9]+)\\.([0-9]+)% Is My String \\+([0-9]+) And Some Extra Stuff Here");
  9.  
  10. std::smatch match;
  11.  
  12. if (std::regex_match(input, match, rx))
  13. {
  14. for (std::size_t i = 0; i < match.size(); ++i)
  15. {
  16. std::ssub_match sub_match = match[i];
  17. std::string num = sub_match.str();
  18. std::cout << " submatch " << i << ": " << num << std::endl;
  19. std::cout << " match str " << i << ": " << match[i].str() << std::endl;
  20. }
  21. }
  22. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
 submatch 0: +10.7% Is My String +5 And Some Extra Stuff Here
 match str 0: +10.7% Is My String +5 And Some Extra Stuff Here
 submatch 1: 10
 match str 1: 10
 submatch 2: 7
 match str 2: 7
 submatch 3: 5
 match str 3: 5