Skip to content

Instantly share code, notes, and snippets.

@clarkli86
Created November 15, 2013 07:28
Show Gist options
  • Save clarkli86/7480510 to your computer and use it in GitHub Desktop.
Save clarkli86/7480510 to your computer and use it in GitHub Desktop.
Count the pattern matches with boost regex
int FindPatternInFile(const char * file)
{
ifstream inFile;
inFile.open(file);//open the input file
stringstream strStream;
strStream << inFile.rdbuf();//read the file
string str = strStream.str();//str holds the content of the file
boost::regex e("m{1000000}");
boost::match_results<string::const_iterator> what;
string::const_iterator begin = str.begin();
string::const_iterator end = str.end();
int count = 0;
while(boost::regex_search(begin, end, what, e))
{
begin = what[0].second;
++count;
}
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment