I have a bunch of java source files and want to list the interfaces implemented by each class in the sources.
The best case is when a class is declared in one line
class MyClass implements MyInterfaceA, MyInterfaceB {
However, there are classes that are declared in multiple lines
class SomeClass
implements
InterfaceC,
InterfaceD
{
So, basically, if I can have a regex that can capture everything between the first implements string literal and the first occurrence of character {, I have the names of implementing interfaces.
For the last hour or so, I've been tinkering with several tools like grep, pcregrep, sed and awk and finally arrived at one command that seems to work.
pcregrep -M 'class[\s\S]*implements'
As you can see, I am trying to output everything between the words class and implements and the command outputs the lines
class SomeClass
implements
When I modify the same expression to output everything between implements and {, it outputs much more than I require, perhaps because there are so many { in the file and/or because { is a special character.
How do I output just the text between the first implements and the first { after that?