Excluding a specific substring from a regex

Posted by Matt S on Stack Overflow See other posts from Stack Overflow or by Matt S
Published on 2010-05-06T18:09:03Z Indexed on 2010/05/06 18:18 UTC
Read the original article Hit count: 181

Filed under:
|

I'm attempting to mangle a SQL query via regex. My goal is essentially grab what is between FROM and ORDER BY, if ORDER BY exists.

So, for example for the query: SELECT * FROM TableA WHERE ColumnA=42 ORDER BY ColumnB it should capture TableA WHERE ColumnA=42, and it should also capture if the ORDER BY expression isn't there.

The closest I've been able to come is SELECT (.*) FROM (.*)(?=(ORDER BY)) which fails without the ORDER BY.

Hopefully I'm missing something obvious. I've been hammering in Expresso for the past hour trying to get this.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about regex