I have the following string with a SQL command:
string sql = "select [x] from table where field = [y] order by [w], [z]";
I would like to get the keys inside the [brackets] (x, y, w, z, etc…), how could I do this with C#? Is there any way to do it with regex (not necessary)?
I try to do something with while statement but it does not work.
Thank you
Using Regex:
This will capture the letter inside the
[]when using theMatchesmethod ofRegex.Since you may have words inside the brackets, the regex is somewhat more complicated.
I will assume that these will never include an escaped
]– so the following should work:Usage:
Note that there is a default group in
match.Groups, so you will get duplicates.