tags:

views:

33

answers:

1

Hi,

I want to extract the parameters names from a query like this:

select * from table where a = :param1 and b = :param2

I wrote this expression:"(?<param>:\w* )"

It gives me :param1 twice

Note: It's in a C#.Net application.

Any Help !!

Thanks

+1  A: 

I tried this C# code - it fetches two matches, one for :param1 and another for :param2

Regex getParamRegex = new Regex(@"(?<param>:\w*)", RegexOptions.Compiled | RegexOptions.IgnoreCase);

string input = "select * from table where a = :param1 and b = :param2";

var allMatches = getParamRegex.Matches(input);

foreach (var match in allMatches)
{
   string work = match.ToString();
}
marc_s
Thanks marc_s, I had a problem in C# fetching code, I was fetch matches using Groups collection by group name, now It's ok.
Homam