test boost regex_match

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include <iostream>
#include <string>
#include <boost/regex.hpp>
int main() {
boost::regex re("^(\\-|\\+|[0-9]).*([^0-9]).*$");
std::string str("0125a24612");
if(boost::regex_match(str, re)) {
std::cout<<"Have"<<std::endl;
} else {
std::cout<<"Do not have"<<std::endl;
}
return 0;
}