Is there a library that would let me write regexp-like queries for lists of objects, just like java.util.regexp matches against strings, which are conceptually like lists of characters?
I want to be able to use patterns with greedy/conservative quantifiers, identifying groups in matches, etc. Obviously I would have to provide the code for matching a query token against an object in the list.
I’m not just trying to save time not writing my own query parser. I’m aware that regexp implementations (against strings) are a well researched area, and Sun’s java.util.regex has surely had the hell optimized out of it long ago. Anything I write won’t be nearly as efficient, and I might have to handle quite long lists (but pretty simple queries).
Thanks!
An idea, if the objects you store in the list are limited, is to create a Map between the object in the list and a Unicode character unique to that object. So given your list you will generate a string of characters that uniquely represent you list.
After that you can use the existing regex packages against the generated string and match anything you wish. After that you can map back to the List.