fork download
  1. #include <iostream>
  2. #include <regex>
  3. using namespace std;
  4. int main()
  5. {
  6. string var = "8 * X^0 - 6 * X^1 + 5.6 * X^2 = 3 * X^0";
  7.  
  8. regex wsaq_re( "(=?\\s*\\-?\\s*\\d+\\s*\\*\\s*X\\s*\\^\\d+)");
  9. copy( sregex_token_iterator(var.begin(), var.end(), wsaq_re, 1),
  10. sregex_token_iterator(),
  11. ostream_iterator<string>(cout, "\n"));
  12.  
  13. return 0;
  14. }
  15.  
Success #stdin #stdout 0s 3560KB
stdin
Standard input is empty
stdout
8 * X^0
 - 6 * X^1
6 * X^2
= 3 * X^0