logo CodeStepByStep logo

regex11

Language/Type: General regular expressions
Author: Melissa Hovik (on 2018/06/01)

Write a regular expression that accepts simple SQL select statements. That is, any SQL statement that starts with "SELECT" followed by one or more comma-separated column names, followed by a single "FROM" keyword followed by one or more comma-separated table names and finished by an optional semi-colon (;).

A valid column or table name contains only letter characters (no spaces, numerical, or special characters), except that a column name (between SELECT and FROM) may optionally include a single "." within the string (not at the start or end). SELECT and FROM must both be uppercased, but the rest of the string may be in any letter-casing format.

For example, the following four strings should match:

SELECT puppy FROM puppies;
SELECT pokemon.name, pokemon.nickname, type FROM pokemon;
SELECT FrOm FROM SeLeCT
SELECT quilts, quarts, quinoa FROM Qstore;
        

But the following five strings should not match:

FROM puppies SELECT puppy;
SELECT puppy FROM p.uppies;
SELECT .name, FROM puppies;
select foo from bar;
SELECT puppy FROM puppies WHERE puppy='mowgli';
        
regex

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.