Regular expressions are a weakness of mine.
I am looking for a regex or other technique that will allow me to read an arbitrary string and determine if it is a valid java function.
Good:
public void foo()
void foo()
static protected List foo()
static List foo()
Bad:
public List myList = new List()
Code:
For String line : lines.
{
If(line.matches("(public|protected|private)*(/w)*(")
}
Is there such a regex that will return true if it's a valid java function?
/^\s*(public|private|protected)?\s+(static)?\s+\w+\s+\w+\s*\(.*?\)\s*$/m
Matches:
This is FAR from complete, but ought to suit your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With