Suppose you want to do regular expression search and extract over a pipe, but the pattern may cross multiple lines, How to do it? Maybe a regular expression library work for a stream?
I hope do this job using Python library? But any solution will be OK, a library not a cmd line tool of course.
BTW, I know how to solve my current problem, just seeking a general solution.
If no such libray exists, why regular library can not work with stream given the regular mathing algorithm never need backward scaning.
If you are after a general solution, your algorithm would need to look something like:
match.end()and go to step 2.This could end up using a lot of memory if no matches are found, but it is difficult to do better in the general case (consider trying to match
.*xas a multi-line regexp in a large file where the onlyxis the last character).If you know more about the regexp, you might have other cases where you can discard part of the buffer.