You aren't going to be able to validate a programming language with regex, for the same reason you can't validate HTML with regex. It's not regular.
Imagine this (pseudo code):
class foo {
function barbar() {
if(foobar) {
case(bar) {
'x': ... break;
'y':
if(foofoo) {
...
return "}";
}
}
}
}
}
You'll never be able to handle all of the scenarios in regex. You need a true parser. You can write your own or use a library, but you definitely cannot rely on regex for this.