views:

33

answers:

2

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?

+1  A: 

You're trying to put a word boundary after the @, rather than before. Maybe this:

\w(@[A-Z0-9a-z]+)

or

\w(@[^\s]+)

Joel Coehoorn
+1  A: 

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|$/
imightbeinatree at Cloudspace