How to extract parameters names from SQL statement using regular expression
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: I开发者_如何学Got's in a C#.Net application.
Any Help !!
Thanks
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();
}
精彩评论