c++ std::regex doesn't match as expected -
c++ std::regex doesn't match as expected -
i've tried implement simple string-test method using c++ std::regex, in ms vc++ 2012.
const std::string str = "1.0.0.0029.443"; if ( std::regex_match( str, std::regex( "\\.0\\d+" ) ) ) std::cout << "matched." << std::endl;
i guessed code match ".0029" part of given str. however, doesn't match @ all. tried on http://regex101.com/ , worked.
use std::regex_search
instead homecoming submatch.
const std::string str = "1.0.0.0029.443"; std::regex rgx("(\\.0[0-9]+)"); std::smatch match; if (std::regex_search(str.begin(), str.end(), match, rgx)) { std::cout << match[1] << '\n'; }
c++ regex
Comments
Post a Comment