WhyIsThatWrong
WhyIsThatWrong

Reputation: 23

Java Parse class name from sources

I'm trying to parse the class name:

public class Script {


}

And I'm using regex at the moment but it doesn't work as good as I though, my regex

class\s+(.*?)\W

But when things like extends and implemented comes in it's breaking itself.

I'm making a script that downloads sources from pastebin and auto saves it.

Thanks.

Upvotes: 1

Views: 499

Answers (2)

fluminis
fluminis

Reputation: 4089

This could do the trick :

serach for all characters excepts spaces or bracket class\s+([^\s{]+)\s*

Upvotes: 2

Katai
Katai

Reputation: 2937

Try to use class\s+(\w*)\s*

This would also handle the case of class Classname{ whitout a space after the Classname

Upvotes: 1

Related Questions