Spotting lowercase SQL code

We want to check where our programmers are using lowercase SQL reserved words, ie "select" instead of "SELECT".
Obviously, we should not raise a warning for code which is commented out with "//".
Suppose I have this input:

select * from mytable
SELECT * from mytable
// select * from mytable statement, but as a comment
select * from mytable statement outside the comment //

So the following code does not work, because it does not return the last line:

grep select myfile.cpp | grep -v "//"

How do I change the expression so that lines with lowercase "select" are returned and which are not preceded by "//"?

Use sed to delete the comments from the stream, then grep for select case-insensitive:

sed 's#//.*##' filename | grep -i select

Here I am using # instead of / to delineate the regex in sed to avoid needing crazy escaping like \/\/ to match forward slashes. You can use any delimiter you want in sed, / is just traditional...

Works great, thank you. Prefer to have the lowercase only, though, which would require:

sed 's#//.*##' myfile.cpp | grep select