views:

1847

answers:

2

I have a list of wild card based patter in a XML file. If the input string matches the pattern present in the XML doc, then a specific action would be taken.

I did find the approach mentioned here http://www.codeproject.com/KB/recipes/wildcardtoregex.aspx but in that case, I need to create a RegEx object for every entry in the XML which I am trying to avoid.

Let me know is there any better way to do wild card search in .net

A: 

It's way past my bedtime, so I may sound quirky on this answer.

It seems to me that you have things set up the wrong way: You're matching an input string against a list of patterns. Logically, you should be matching each pattern in the list against the input string and determining a match. It should be quite straightforward to construct an array of Regex patterns by parsing the XML file. Then you can iterate through the array and match each Regex against your input string.

Additionally, Why do you need wildcards at all? Wildcards can be considered a subset of Regex and so you already have all the functionality of wildcard matching encapsulated within the Regex object.

That said, more data on the type of input/wildcards may prove helpful to understand your question.

Cerebrus
A: 

Hi

If you wish to evaluate each pattern in you document to match against the input string, you'll have to create a RegEx for each pattern, like you mention. There's no shortcut.

I guess you worry about perfomance. Are you sure it's a problem? If so, you should try to find a different approach altogether.

Are you going to match many input strings? In that case, you should keep your RegExes (in a list, say) rather than creating them each time. RegExes can be reused.

Otherwise, I can see no big problem with your proposed approach.

Tor Haugen