Regex search pattern in very large file

后端 未结 2 2036
名媛妹妹
名媛妹妹 2020-12-16 20:18

I\'d like to search pattern in very large file (f.e above 1 GB) that consists of single line. It is not possible to load it into memory. Currently, I use BufferedRead

相关标签:
2条回答
  • 2020-12-16 21:05

    I think the solution for you would be to implement CharSequence as a wrapper over very large text files.

    Why? Because building a Matcher from a Pattern takes a CharSequence as an argument.

    Of course, easier said than done... But then you only have three methods to implement, so that shouldn't be too hard...


    EDIT I took the plunge and I ate my own dog's food. The "worst part" is that it actually works!

    0 讨论(0)
  • 2020-12-16 21:05

    It seems like you may need to break that search-pattern down into pieces, since, given your restrictions, searching for it in its entirety is failing.

    Can you determine that a buffer contains the beginning of a match? If so, save that state and then search the next portion for the next part of the match. Continue until the entire search-term is found.

    0 讨论(0)
提交回复
热议问题