Java Search Pattern RegularExpression Style
My Question is the following:
Is there a Pattern-Builder in Java which can be feeded with input and builds a search/regex pattern for it?
What i have: Load the List of names. Start reading the file, and check each line with the full List of Names. (This creates a Cartesian product, but I don't want that).
What i want to achieve: Load List of Names which should be considered for the regular expressions Create Pattern and load all the names into the pattern. Read the first file and check it with the pattern.
So you can see that I would like to reduce the Cartesian product down to an O[n] sequence to save performance.
Conditions: The Regular Expression pattern should be loaded from a list, so it will be dynamic. The input can be anything, the output should be an alert in case any of the names matches.
If you think I have not provided enough please ask, ill be glad to provide more information wherever I can.
What you can do is to create a Set with names. This will guarant you to have distinct list of name with O(1) access time. Then you can check that name from line in the file exists in that set.
But this might not be perfect solution. To gain more help you should provide the file preview and example input and output.
Unfortunately dasblinkenlight has put in the answer in the comments,
The results of compiling such a huge pattern is alright, i tried it with a 4.5 MB pattern. I hope there is no limitation to that.