Performing regex on a stream

Posted by takoi on Stack Overflow See other posts from Stack Overflow or by takoi
Published on 2010-06-10T10:49:47Z Indexed on 2010/06/10 10:52 UTC
Read the original article Hit count: 207

Filed under:
|

I have some large text files which im going to preform consecutive matching on (just capturing, not replacing). Im thinking its not such a good idea to keep the whole file in memory, but rather use a Reader.

What i know about the input is that if there's a match, its not going to span more than 5 lines. So my idea was to have some sort of buffer which just keeps these 5 lines, or so, do the first search, and continue. But it has to "know" where the regex match ended for this to work. e.g if the match ends at line 2 it should start the next search from here. Is it possible to do something like this in an efficient way?

© Stack Overflow or respective owner

Related posts about java

Related posts about regex