1

I have a multi-class java file. One of those classes contains a main method (public static void main...). Example:

class one {...}
class two {...}
class three {
   public static void main(String[] args) {...}
}

I tried

class.*?[^.*?]*?main

but that matches starting at class one not class three

1
  • Given the complexity of Java syntax, a regex is not really suited for this. Commented Feb 18, 2016 at 17:25

1 Answer 1

2
\s*static\s*void\s*main\s*\(\s*String\s*\[\]\s*[^\)]*\)

if you want the name of class you can test this regex

class\s*([^\{]*)\{\s*.*static\s*void\s*main\s*\(\s*String\s*\[\]\s*[^\)]*\).*
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.