I have small python script in which I look for a pattern in the standard input, and output it after some reformatting. I have removed the complex pattern and reformatting code from the example.
Currently my code looks like this.
for line in re.finditer(r"""(.*)\n""", sys.stdin.read(), re.MULTILINE):
print(line.group(0))
Notice the “sys.stdin.read()”. This causes the script to buffer the whole input before it looks for a pattern.
How can I pass stdin as a buffer to finditer, so stdin will searched as it is inputted to the script instead of having it buffered first?
Apparently I missed this before I asked my question, It is already answered.
Python regex parse stream
Unfortunately it’s an issue with the implementation of regex in python.
See the link for possible workarounds.