views:

62

answers:

2

Before I look into doing this myself, is there already a function out there that will do this:

I want to pass in a string containing text and RegEx markup and then it returns all possible matches it would look for in a string.

so the following passed to the method

abc|def|xyz

Would return 3 strings in an array or collection:

abc
def
xyz

Because that regex notation says to look for either abc, def or xyz.

I don't want this to search for the term in another string or anything like that, just return the possible matches it could make.

That's a simple example, anything that will do this for me, or shall I start writing the method myself?

+1  A: 

With a simple regex as per your example it will work, but as soon as you start dealing with wild cards and repetition, it will have to generate almost an infinite amount of possible solutions, which in some cases may never even terminate.

leppie
You haven’t hard of lazy evaluation, have you? :) It’s easily possible to generate an `IEnumerable` that never ends and is nonetheless useful.
Timwi
@Timwi: Well that will never return all possible matches, so it's pretty useless (as a solution to the question).
leppie
@Ieppie: The answer to the question is that .NET doesn’t provide such a function. Your answer, however, gives a speculative and specious reasons as to *why* it doesn’t.
Timwi
@Ieppie: Also, I didn’t know that a solution that gets as close as possible is “useless” and no solution at all is somehow more useful?
Timwi
@Timwi: You would have to read Dick Grune's book on parsing to understand why.
leppie
@Ieppie: LOL, when you know nothing better to respond, just point to an irrelevant book :-D
Timwi
+1  A: 

No, it does not :)

Max