@haruhiku I agree, applying regex always gave me a sense of cheating.

My C++ solution without regex but some basic string operations:

pair<int,int> analyzeHalve(string &s){
if(s[0] == '+' || s[0] == '-') s.insert(s.begin(),'0');
int sign = 1, a = 0, b = 0;
for(int i = 0; i < s.size(); ++i){
int pos = s.find_first_of("+-", i);
if(pos == string :: npos) pos = (int)s.size();
string tmp = s.substr(i, pos -i);
if(tmp.back() == 'x'){
tmp.pop_back();
a += sign * (tmp.size() == 0 ? 1 : stoi(tmp) );
}
else
b += sign * ( stoi(tmp) );
sign = s[pos] == '+' ? 1 : -1;
i = pos;
}
return {a, b};
}
string solveEquation(string equation) {
string lHalve, rHalve;
stringstream ss(equation);
getline(ss, lHalve, '=');
getline(ss, rHalve, '=');
auto p1 = analyzeHalve(lHalve);
auto p2 = analyzeHalve(rHalve);
if(p1.first == p2.first){
if(p1.second == p2.second) return "Infinite solutions";
else return "No solution";
}
else {
int ans = (p2.second - p1.second) / (p1.first - p2.first);
return "x=" + to_string(ans);
}
}