Skip to content

Instantly share code, notes, and snippets.

@kyle-go
Last active January 27, 2016 03:40
Show Gist options
  • Save kyle-go/e36a6819c859079f2989 to your computer and use it in GitHub Desktop.
Save kyle-go/e36a6819c859079f2989 to your computer and use it in GitHub Desktop.
c++ regex
#include "stdafx.h"
#include <regex>
using namespace std;
int main()
{
string str = "xxxABC999yjdskABC444阿凡ABC0_达ABC77汉字eABC9";
const regex reg("ABC[0-9]+");
smatch results;
std::string::const_iterator it = str.begin();
std::string::const_iterator end=str.end();
vector<string> v;
while (regex_search(it, end, results, reg)) {
v.push_back(results[0]);
it=results[0].second;
}
for (auto it = v.begin(); it != v.end(); it++) {
printf("%s\n", it->c_str());
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment