Given a sql query with some columns that have upper case letters, how can I search for words that contain a upper case letter but not SQL keywords, for example:
SELECT ... ,
table1.thisColumn AS column,
...
FROM table1
I’ve tried without success to build something like this:
(?!AS+FROM+LEFT+JOIN+ON)[A-Z]{2,}
Two things to note about your existing regex.
|and not a+. The+will be treated as an actual character whereas the|will tell the regex engine “left” or “right”, as you want in this case.I’ve come up with the following:
I tested this against your sample query and also added other random SQL to it (such as an expanded field list,
WHEREclause, etc.). It successfully found each word that contained at least one capital letter and was not in the list of keywords to ignore.If you’re using this to just “search” via
Find NextorFind All in Opened|Current Documents, it will highlight the matching word and a preceding.or whitespace character(s).If you’re using this to “replace”, the matched word (without the preceding
.or whitespace character(s)) can be used/accessed via the\1match.Regex Explained:
You’ll also want to add in any missing SQL keywords (if needed), or other allowed characters in the “words can have these characters” list.