My question is very similar to this one
Java: method to get position of a match in a String?
Except that I will be searching through very long strings (hundreds of megabytes) so I would like for the method to give up after a certain index.
Something like this except with an end index as well. Is there a library that provides this functionality?