Skip to content

Instantly share code, notes, and snippets.

@hyqhyq3
Created May 3, 2014 15:55
Show Gist options
  • Save hyqhyq3/7ea24148d9792ff69664 to your computer and use it in GitHub Desktop.
Save hyqhyq3/7ea24148d9792ff69664 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <boost/regex.hpp>
#include <iostream>
int main()
{
boost::regex e("(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])");
boost::match_results<std::string::const_iterator> what;
const std::string str("哈哈哈 8.8.8.8 1.2.3.4 256.256.247.1");
auto first = str.begin();
auto last = str.end();
std::cout << "string is " << str << std::endl;
while(boost::regex_search(first, last, what, e))
{
std::cout << std::string(what[0].first, what[0].second) << std::endl;
first = what[0].second;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment