Maybe it is an idea to temporarily cut all string out of the source code and then search for the variable name.
Assuming the source code is valid (no syntax errors), you can cut everything from the first occuring double quote (") to the next double quote.
Notice that variable names with just one character (like d) will require some additional code, for d is also used for forcing the compiler as interpreting the preceding number as a double (e.g. double dbl = 6d).
EDIT: I was assuming that you wanted to build an application or piece of code which lightweight-checked for variable names.
If you work inside an editor, I recommend you to use an advanced editor like Netbeans or Eclipse.
Otherwise, if you want to also check for correct syntax, you'll need to build your own interpreter (or download some from internet).