You may want to look at Matching in huge files, which uses a sliding window technique to match in large files.
In reply to Re: How regexes fail. by kyle in thread How regexes fail. by jdoege