I'm trying to extract a word phrase from a Java source file. For example I have a simple source class
class TestClass implements TestInterface implements TestInterface2 {
}
class TestClass2 {
}
I want to extract the "class TestClass" and "class TestClass2". I have tried different regex patterns but couldn't find a solution
My testing code spinet:-
public static void wordPhraser(String sourceText) {
Pattern p = Pattern.compile("class(\\s+)([a-zA-Z]*)");
Matcher m = p.matcher(sourceText);
while (m.find()) {
System.out.println("output " + m.group());
}
}
Also tried:-
"class\\s*([a-zA-Z])"
"class\\s*[a-zA-Z]"
"^class\\s+[a-zA-Z]$"
Non of these are working.
Thanks.