Python regex parse stream

前端 未结 4 680
失恋的感觉
失恋的感觉 2020-12-09 15:03

Is there any way to use regex match on a stream in python? like

reg = re.compile(r\'\\w+\')
reg.match(StringIO.StringIO(\'aa aaa aa\'))

And

4条回答
  •  执笔经年
    2020-12-09 15:43

    This seems to be an old problem. As I have posted to a a similar question, you may want to subclass the Matcher class of my solution streamsearch-py and perform regex matching in the buffer. Check out the kmp_example.py for a template. If it turns out classic Knuth-Morris-Pratt matching is all you need, then your problem would be solved right now with this little open source library :-)

提交回复
热议问题