Reputation: 1247
Trying to parse an SQL string and pull out the parameters.
Ex: "select * from table where [Year] between @Yr1 and @Yr2"
I want to pull out "@Yr1" and "@Yr2"
I have tried many patterns, but none has worked, such as:
matches = Regex.Matches(sSQL, "\b@\w*\b")
and
matches = Regex.Matches(sSQL, "\b\@\w*\b")
Any help?
Upvotes: 0
Views: 180
Reputation: 468
I would have gone with
/^|\s(@\w+)\s|$/
or if you didn't want to include the @
/^|\s@(\w+)\s|$/
though I also like joel's above, so maybe one of these
/^|\s(@[^\s]+)\s|$/
/^|\s@([^\s]+)\s|$/
Upvotes: 1
Reputation: 416049
You're trying to put a word boundary after the @, rather than before. Maybe this:
\w(@[A-Z0-9a-z]+)
or
\w(@[^\s]+)
Upvotes: 1