fork download
  1. #include <iostream>
  2. #include <regex>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. const auto input = "-f name -b blah blah -e email"s;
  9. smatch m;
  10.  
  11. if(regex_search(input, m, regex{ "(?:\\s*-f\\s+(\\w+)|\\s*-b\\s+([^-]+)|\\s*-e\\s+(\\w+))*" })) {
  12. if(m[1].length() > 0U) {
  13. cout << "-f " << m[1] << endl;
  14. }
  15.  
  16. if(m[2].length() > 0U) {
  17. cout << "-b " << m[2] << endl;
  18. }
  19.  
  20. if(m[3].length() > 0U) {
  21. cout << "-e " << m[3] << endl;
  22. }
  23. }
  24. }
Success #stdin #stdout 0s 4280KB
stdin
Standard input is empty
stdout
-f name
-b blah blah 
-e email