fork(1) download
  1. #include <string>
  2. #include <iostream>
  3. #include <regex>
  4. using namespace std;
  5.  
  6. int main() {
  7. std::string pat = R"(\s*(.*?)\s*=\s*(\"(.*?(?:[\\]\".*?)*)\")\s*([,|.*?]))";
  8. std::regex r(pat);
  9. std::cout << pat << "\n";
  10.  
  11. std::string s = R"(data1 = "value 1", data2 = "value 2", data3 = " data4(" hey ") ",)";
  12. std::cout << s << "\n";
  13. for(std::sregex_iterator i = std::sregex_iterator(s.begin(), s.end(), r);
  14. i != std::sregex_iterator();
  15. ++i)
  16. {
  17. std::smatch m = *i;
  18. std::cout << " Capture 1: " << m[1].str() << " at Position " << m.position(1) << '\n';
  19. std::cout << " Capture 3: " << m[3].str() << " at Position " << m.position(3) << '\n';
  20. }
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 3500KB
stdin
Standard input is empty
stdout
\s*(.*?)\s*=\s*(\"(.*?(?:[\\]\".*?)*)\")\s*([,|.*?])
data1 = "value 1",   data2 = "value 2",  data3 = " data4(" hey ") ",
    Capture 1: data1 at Position 0
    Capture 3: value 1 at Position 9
    Capture 1: data2 at Position 21
    Capture 3: value 2 at Position 30
    Capture 1: data3 at Position 41
    Capture 3:  data4(" hey ")  at Position 50