-1

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.

Delimitry
  • 2,987
  • 4
  • 30
  • 39
Juanpe Araque
  • 579
  • 1
  • 4
  • 16

1 Answers1

4

Gcc 4.8.2 does not support regex. You need 4.9

Manuel Barbe
  • 2,104
  • 16
  • 21