I have a set of strings like this violet+2, orange-3 and things like that. It is a way to name colours. I want to get the color, operation and number with regex using this piece of code:
int parseColor(string color){
smatch sm;
int ret = -1;
if (regex_match(color,sm,regex("(.*)([+-])(.*)")))
ret = s_colors[sm[1].str()]+s_colors[sm[2].str()]*atoi(sm[3].str().c_str());
return ret;
}
where s_colors is a map that matches each colour to a integer value and the +,- sign to +1 and -1.
I have tried also scaping the +- signs with \\+ and \\- but it doesn't work either. Every time I run I get regex_error. Trying this in ruby seems to work so... I am not sure what is the error with the regex.