fork download
  1. #include <string>
  2. #include <iostream>
  3. #include <regex>
  4. using namespace std;
  5.  
  6. int main() {
  7. std::regex r(R"((\$*[A-Z][A-Z\d_]*)\s*=\s*((?:(?![A-Z]\d+\.\d+|[A-Z][A-Z\d_]*\s*=).)*))");
  8. std::string s = "N100$VAR1=100+$Var2*30 + #29X=30.99Z=(#991+ ( 30*SIN(60) + $VAR32 ) / #32)";
  9. for(std::sregex_iterator i = std::sregex_iterator(s.begin(), s.end(), r);
  10. i != std::sregex_iterator();
  11. ++i)
  12. {
  13. std::smatch m = *i;
  14. std::cout << "Match value: " << m.str() << '\n';
  15. std::cout << " Capture: " << m[1].str() << '\n';
  16. std::cout << " Capture: " << m[2].str() << '\n';
  17. }
  18. return 0;
  19. }
  20.  
Success #stdin #stdout 0s 3556KB
stdin
Standard input is empty
stdout
Match value: $VAR1=100+$Var2*30 + #29
    Capture: $VAR1
    Capture: 100+$Var2*30 + #29
Match value: X=30.99
    Capture: X
    Capture: 30.99
Match value: Z=(#991+ ( 30*SIN(60) + $VAR32 ) / #32)
    Capture: Z
    Capture: (#991+ ( 30*SIN(60) + $VAR32 ) / #32)