Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular expression

Status
Not open for further replies.

byleth

Programmer
Feb 27, 2004
70
PT
hi,

I'm trying to build a regex that catches everything between a FROM and WHERE of a sql clause (ie, the tables)


EX: select * from t1, t2,t3, t4 x where ...

i need the "t1, t2,t3, t4 x"


i've tried several stuff and end up with this

FROM\s+(?<tables>\w+\s*[,]?\s*)*(WHERE){0,1}


but in <tables> value i get "WHERE"

also the expression also matches the FROM and WHERE words, and i only need the tables.



thanks in advance
 
The principle that you need to follow is demonstrated quite clearly in my reply to your previous request for Regular Expression help. That is the one to which you did not bother to reply.


Hope this helps.

[vampire][bat]
 
If you haven't already come up with a solution then:

[tt](?<= FROM ).*(?= WHERE )[/tt]

should do what you need.

A couple of caveats:

The space is required either side of both FROM and WHERE
This does not provide proper support for nested or sub SELECT statements

If you cannot guarantee the case of FROM and WHERE set the IgnoreCase parameter

Code:
'assumes Imports System.Text.RegularExpressions

    Dim rx As New Regex(TextBox1.Text, RegexOptions.IgnoreCase)
    For Each m As Match In rx.Matches(TextBox2.Text)
      MessageBox.Show(m.ToString)
    Next

'TextBox1 contains the match pattern and TextBox2 contains the SQL statement

Hope this helps.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top