fork(1) download
  1. #include <iostream>
  2. #include <regex>
  3. #include <string>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. string input("tag = value\ntag2 = value2\nvalue continuation2\n# comment for tag3\ntag3 = value3");
  10.  
  11. const regex re("(?:\\s*#.*\\n)*(\\w+)\\s*=\\s*((?:[^#=\\n]+(\\n|$))+)");
  12.  
  13. for (sregex_iterator i(input.cbegin(), input.cend(), re); i != sregex_iterator(); ++i) {
  14. const string tag = i->operator[](1);
  15. const string value = i->operator[](2);
  16.  
  17. cout << tag << ':' << value << endl;
  18. }
  19. }
Success #stdin #stdout 0s 3500KB
stdin
Standard input is empty
stdout
tag:value

tag2:value2
value continuation2

tag3:value3