2

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
  • What language is running the Regular Expression: Perl, Java, etc. This can alter the syntax slightly. Commented Jul 4, 2010 at 14:27

1 Answer 1

3

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();
}
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.