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?

The example:

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.

Need Your Help

A parent record isn't added to a database after a child record has been added

c# database entity-framework ef-code-first relational-database

I'm trying to create a database containing a single self-referenced table "Categories" using Code First approach. Here is the definition of the Category POCO entity:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.