Created
November 15, 2013 07:28
-
-
Save clarkli86/7480510 to your computer and use it in GitHub Desktop.
Count the pattern matches with boost regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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