In the regex_search function, the first matching result is saved to an smatch class.
However, if the search string contains multiple matching results, you must implement it yourself.
In smatch, there are two members. The official documents are as follows:
Iterator first:
An iterator denoting the position of the start of the match.
Iterator second
An iterator denoting the position of the end of the match.
Therefore, use the following method to obtain the traversal search:
#include <string>#include <iostream>#include <boost\regex.hpp>int main(){ std::string str = "192.168.1.1"; boost::regex expression("\\d+"); boost::smatch what;std::string::const_iterator start = str.begin();std::string::const_iterator end = str.end(); while ( boost::regex_search(start, end, what, expression) ) {std::cout << what[0] << std::endl;start = what[0].second; }return 0;}
The result is as follows:
19216811
Use boost RegEx's regex_search for traversal and search