- regex_match , () . , , , - . , , , ( Kleene). , , , - regex_token_iterator.
Edit: , ++, . , , - , . , , , "+", "-" "^", . , "^". , , , . , - : "[- +]? (\ D *) x (\ ^ ([0-9]) *)".
, - :
#include <iterator>
#include <regex>
#include <string>
#include <iostream>
int main() {
std::string poly = "4x^2+3x^1+2x";
std::tr1::regex term("[-+]?(\\d*)x(\\^[0-9])*");
std::copy(std::tr1::sregex_token_iterator(poly.begin(), poly.end(), term),
std::tr1::sregex_token_iterator(),
std::ostream_iterator<std::string>(std::cout, "\n"));
return 0;
}
, :
4x ^ 2
+ 3x ^ 1
+ 2
, , , (, ).
: std::cout, - :
#include <iterator>
#include <regex>
#include <string>
#include <iostream>
int main() {
std::string poly = "4x^2+3x^1+2x";
std::tr1::regex term("[-+]?(\\d*)x(\\^[0-9])*");
std::vector<std::string> terms;
std::copy(std::tr1::sregex_token_iterator(poly.begin(), poly.end(), term),
std::tr1::sregex_token_iterator(),
std::back_inserter(terms));
return 0;
}