C ++ regular expression downstream

I have a very large text file (up to several hundred MB) that I would like to process with the regular expression STL. The matching area I am looking for spans several lines and occurs at least several thousand times in the file.

Can I use stream iterators for this purpose? I tried std :: istream_iterator but no luck. Can I post a minimal working example?

Please note that I am looking for a solution that includes only STL. In an ideal solution, I would like to iterate over all matches.

EDIT

As soon as I read the comment, I understand that this is not possible. So there may be another way to iterate over regular expression matches that can be found in a large text file:

#include <regex> #include <iostream> #include <string> const std::string s = R"(Quick brown fox jumps over several lines)"; // At least 200MB of multiline text here int main(int argc,char* argv[]) { std::regex find_jumping_fox("(Quick(?:.|\\n)+?jump\\S*?)"); auto it = std::sregex_iterator(s.begin(), s.end(), find_jumping_fox); for (std::sregex_iterator i = it; i != std::sregex_iterator(); ++i) { std::smatch match = *i; std::string match_str = match.str(); std::cout << match_str << '\n'; } } 
+5
source share

Source: https://habr.com/ru/post/1234284/


All Articles