RegularExpression-esque search matching Objects in List
Posted
by Pindatjuh
on Stack Overflow
See other posts from Stack Overflow
or by Pindatjuh
Published on 2010-04-16T00:10:45Z
Indexed on
2010/04/16
0:13 UTC
Read the original article
Hit count: 335
I'm currently working on an implementation of the following idea, and I was wondering if there is any literature on this subject.
Working with Java, but the principle applies on any language with a decent type-system, I like to implement: matching Object
s from a List
using a RegularExpression-esque search:
So let's say I have a List
containing
List<Object> x = new ArrayList<Object>();
x.add(new Object());
x.add("Hello World");
x.add("Second String");
x.add(5); // Integer (auto-boxing)
x.add(6); // Integer
Then I create a "Regular Expression" (not working with a stream of characters, but working with a stream of Object
s), and instead of character-classes, I use type-system properties:
[String][Integer]
And this would match one sublist: {Match["Second String", 5]}
. The expression:
[String:length()<15]
Will match two sublist (each of length 1) containing a String
which instance is passing the expression instance.length() < 5
: {Match["Hello World"],Match["Second String"]}
.
[Object][Object]
Matches any pair in the List
: {Match[Object,"Hello World"],Match["Second String", 5]}
, in a streamed manner (no overlapping matches).
Ofcourse, my implementation will have grouping, lookahead/lookbehinds and is hierarchical (i.e. matching n
elements from List
s in List
s), etc. The above merely illustrates the concept.
Is there a name for this principle, and is there literature available on it?
© Stack Overflow or respective owner