fork download
  1. #include <iostream>
  2. #include <regex>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.  
  9. std::string sconf = "TEMP_SOURCE=abcd\n INTERVAL=10\n MIN_SPEED=0\n POLICY=60:250 50:0 30:9\n";
  10. std::smatch m;
  11.  
  12. /*
  13.   * match blank lines, trailing spaces
  14.   * and bash like comments
  15.   */
  16. std::string bc = "(?:\\s*(?:#.*[\r\n])*)*";
  17.  
  18. /*
  19.   * refex to match allowed numbers
  20.   */
  21. std::string num = "([0-9]|10|250)";
  22.  
  23. /*
  24.   * match afsc config file
  25.   */
  26. std::regex r(bc + "TEMP_SOURCE=([-_./[:alnum:]]+)"+
  27. bc + "INTERVAL=(\\d+)"+
  28. bc + "MIN_SPEED=([0-9]|10|250)"+
  29. bc + "POLICY=((?:\\d+:(?:[0-9]|10|250)\\s+)+)" + bc);
  30.  
  31. std::regex_match(sconf, m, r);
  32.  
  33. std::cout <<m.size();
  34. return 0;
  35. }
Success #stdin #stdout 0s 3368KB
stdin
Standard input is empty
stdout
5