tags:

views:

40

answers:

4

I going crazry with regex.

I need to extract a words between FROM and WHERE in this syntax:

SELECT IDClient, Client FROM Client WHERE IDClient = 1 GROUP BY IDClient, Client ORDER BY IDClient

result = Client

How can I resolve this using regular expressions?

A: 

Use a regex cheat sheet, it's not too hard to work out.

fredley
+2  A: 

/FROM (.*) WHERE/i

Jan.
That will return the FROM and WHERE as part of the match which is not what was asked
rrrr
@rrr You can extract `$1` from the match - granted sql regex engine supports that.
Amarghosh
@rrrr OP asked how to get the string between and if you look at the match closely, then you will notice index 0 points to the whole match and match 1 will only show the part in paranthesis. Sadly the question is not very specific so no one knows with what you're performing the regex matching/replacing on that mysql-query.. Any further answer would be wild guessing! And the used tags are misleading…
Jan.
+1  A: 
(?<=FROM\s+).*(?=\s+WHERE)

That uses a look behind and a lookahead to get what is between FROM and WHERE, and can be modified depending on whether you want the whitespace or not.

rrrr
A: 

You can use this online regular expression builder:

Or try the tutorials at:

  • regular-expressions dot info
Rami C