Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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[]"

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.

like image 977
Godisemo Avatar asked Dec 31 '25 00:12

Godisemo


1 Answers

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.

like image 75
Mike Daniels Avatar answered Jan 01 '26 12:01

Mike Daniels