История изменений
Исправление invy, (текущая версия) :
regex match
даже пример под рукой есть
#include <string>
#include <regex>
#include <iostream>
int main() {
std::string title = "Success state=7SpaJQKB9YxXkw63k96ki7PEH7dDA83Q&code=4/-tsm0fDPYwyL_c4hm-sPiVZs7EJk - Google Chrome";
std::string SuccessRegexPattern = ".*Success state=([^\\s]+)\\&code=([^\\s]+).*";
std::string code;
std::string state;
std::regex successRegex(SuccessRegexPattern, std::regex::ECMAScript);
std::smatch match;
bool res = std::regex_match(title, match, successRegex);
std::cout << "match result " << res << "\n";
std::cout << "match size " << match.size() << "\n";
if (match.size() > 2)
{
state = match[1];
code = match[2];
std::cout << state << "\n";
std::cout << code << "\n";
}
else
std::cout << "no match\n";
return 0;
}
Исходная версия invy, :
regex match
даже пример под рукой есть
#include <string>
#include <regex>
#include <iostream>
int main() {
std::string title = "Success state=7SpaJQKB9YxXkw63k96ki7PEH7dDA83Q&code=4/-tsm0fDPYwyL_c4hm-sPiVZs7EJk - Google Chrome";
std::string SuccessRegexPattern = ".*Success state=([^\\s]+)\\&code=([^\\s]+).*";
std::string code;
std::string state;
std::regex successRegex(SuccessRegexPattern, std::regex::ECMAScript);
// successRegex.assign(SuccessRegexPattern);
std::smatch match;
bool res = std::regex_match(title, match, successRegex);
std::cout << "match result " << res << "\n";
std::cout << "match size " << match.size() << "\n";
if (match.size() > 2)
{
state = match[1];
code = match[2];
std::cout << state << "\n";
std::cout << code << "\n";
}
else
std::cout << "no match\n";
return 0;
}