I am currently using java regex matching to look through a very large number of files, and locate all files that match the pattern. I want to be able to show the matching text in context, so the regex pattern I am using is:
[\\S|\\s]{0,30}abc[\\S|\\s]{0,30}
This successfully grabs "abc" as well as up to 30 of any characters on either side.
However, when running this search through my large database of files, the search takes 21 minutes to complete (while removing the padding and searching for just "abc" makes it run in <1 minute).
Is there a reason that my regex runs so slowly? Is there a more efficient way to grab the context?
NOTE: I am just using java.util.regex.Matcher and java.util.regex.Pattern in a loop over each file. I can create a short mockup of the relevant code if needed, though