fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <regex>
  4.  
  5. int main()
  6. {
  7. std::string input = "led=1,vid=2,fc=333,ts=4444";
  8. std::regex rx("led\\=([0-9]+)\\,vid\\=([0-9]+)\\,fc\\=([0-9]+)\\,ts\\=([0-9]+)");
  9.  
  10. std::smatch match;
  11.  
  12. if (std::regex_match(input, match, rx))
  13. {
  14. std::cout << "match size " << match.size() << std::endl;
  15. std::cout << "led " << match[1].str() << std::endl;
  16. std::cout << "vid " << match[2].str() << std::endl;
  17. std::cout << "fc " << match[3].str() << std::endl;
  18. std::cout << "ts " << match[4].str() << std::endl;
  19. }
  20. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
match size 5
led 1
vid 2
fc 333
ts 4444