Get list of possible matches using RegEx

  • Thread starter Thread starter Ryan M
  • Start date Start date
R

Ryan M

Is it possible for me to provide an expression like this:

Product[1-3]

And using the RegEx classes have it give me a string array with all the
possible matches, i.e.:

Product1
Product2
Product3

I don't want to actually perform a match against another string, I just
want to "expand" the expression to it's full form if that makes
sense...

Any ideas appreciated...

-Ryan
 
Ryan said:
Is it possible for me to provide an expression like this:

Product[1-3]

And using the RegEx classes have it give me a string array with all the
possible matches, i.e.:

Product1
Product2
Product3

I don't want to actually perform a match against another string, I just
want to "expand" the expression to it's full form if that makes
sense...

No, there's no automatic functionality that would do this. Consider the
complexity... the sample you're giving is certainly simple, but the
expression could be much more complex - for example, a single * or +
quantifier would immediately allow for an unlimited number of possible
strings.


Oliver Sturm
 
Really? Cause I've seen this done before with perl tools. Maybe it was
a limited implementation of the reg ex expression language.
 
Ryan said:
Really? Cause I've seen this done before with perl tools. Maybe it was
a limited implementation of the reg ex expression language.

I suspect it was a limited application of some sorts. I mean, the problem
is easy enough to see. Consider these two patterns:

a.*b
a[A-Z]{2,5}b

In the first case, there's an unlimited number of possible strings,
because the length of the string between a and b is unlimited. In the
second case, the length is being restricted to something from two to five
characters and the character range is also much smaller - the number of
possible matches is still quite enormous, but at least it's finite.

A place where I've seen functionality that might be confused as similar is
auto-completion in regex based text entry boxes. But this is a scenario
that only looks similar, because the finding of possibe completions is
based on what the user has already entered. For example, in the first case
the entry string might look like this (| being the cursor):

ablah|b

So while the user hasn't typed the b, it could still be shown by the
editor, because the regex clearly shows that it's got to come in
somewhere. That makes the complex sample somehow seem simpler :-)


Oliver Sturm
 
Back
Top