开发者

Match a java main class with regexp

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开发者_JAVA技巧[]"

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜