Suppose I have this simple regular expression search piece of code:
boost::regex re("(\\d+)(/(\\d))?");
boost::smatch matches;
boost::regex_search(input_str, matches, re);
It searches a string for something like 123/2
or 123
. Second digit and / are optional.
I want to know that if /2
is present or not and if it exists set the second number after / to a variable or set the variable to -1 otherwise.
I tried to use matches.size()
, but it's always the same value whether the second part exists or not.