tags:

views:

128

answers:

4

Could someone please tell me which objects types can be tested using Regular Expressions in C#?

+5  A: 

If I understand you correctly and you are asking which object types can be tested against regular expressions then the answer is: strings and only strings.

Thus your test would be:

if(obj is string){...}
Manu
Yes, which object types can tested against regular expressions si what I was looking for.
Michael Kniskern
I have edited your question inline with your comment to this answer.
Xenph Yan
+3  A: 

Regular expressions only apply to strings. What does it even mean to apply a regular expression to (say) a SqlConnection?

If you need some other sort of pattern matching (e.g. being able to match the values of particular properties) you should think about and then explain those requirements in detail.

Jon Skeet
+1  A: 

I suppose you could always use the Regular Expression against Object.ToString(), which could be helpful if you override ToString() to give information about your object that you want to match against.

Ray
A: 
Regex.IsMatch()
ripper234