Difficulty using boost::regex_match to get separate matches for "NASIONAL" and "12" from string "NASIONAL12"

27 views Asked by At

This works fine in all online regex testers but fails to produce any matches in boost::regex_match, which I unfortunately must use as is because it is being used in a system that expects this format for more complicated parsings of street names.

std::string rformat = "(([a-zA-Z]*)|([0-9]*))?";
std::string source = "NASIONAL12";
const boost::regex piecesRegex(rformat);
boost::smatch      piecesMatch;
if (boost::regex_match(source, piecesMatch, piecesRegex))
{
   for (auto match : piecesMatch) {
       std::cerr << "MATCH:" << match << std::endl;
   }
}

What I need is for the first "piecesMatch" to return "NASIONAL" and the second "piecesMatch" to return "12"

1

There are 1 answers

3
StainlessSteelRat On

Thanks to everyone's help I found the right regex string:

([a-zA-Z]*)?([0-9]*)?