views:

64

answers:

1

Hi, I'm writing a plugin for emacs to compile and run a java source file with one keystroke. Now I would like to find out the name of the main class or if there is none. Anyone knows how to match a java main class name with regexp?

My first thought, in pseudo code regex is

  • find the first word preceded by "class " and succeeded by "{"..."public static void main(String[]"

edit- this is how far I've come. Not fully functionally yet but almost...

(?<=class ).*[^ ](?= *{.*public static void main)

I hate regex but still i like it. It's just that it's so hard to master.

+1  A: 

The main class in Java does not have to have any particular name. In fact, a Java project can have several main classes, all with different names.

Mike Daniels
What i really mean is how do I match any class name in my file that contains a main function. Probably should have mad myself clearer.
Godisemo
Regular expressions won't do this.
Anon.