So I'm trying to find functions that follow a pattern that exclude certain text. I know that if I'm looking for the following function
void myfunction(unsigned int a)
{
//Something something here
}
I can find this using the following
grep -IPzor 'void.*myfunction(\n|.)*\{(\n|.)*\}' ./*
and this seems to work properly. There are two things that I can't figure out how to do.
1) What if I wanted to ignore functions that have the phrase 'something' in it?
Let's say I now have the following functions:
void myfunction1(unsigned int a)
{
//Something something here
}
void myfunction2(unsigned int a)
{
//Other stuff here
}
and I only want to find things like function2. I tried to do:
grep -IPzor 'void.*myfunction(\n|.)*\{(\n|.)*(?!Something|something)(\n|.)*\}' ./*
And different variations of this don't work as I'd expect. It just finds nothing, and changing the phrase from 'something' to 'nothing' doesn't help.
2) What if I want to find results where only an equal number of '{' and '}' are found?
For this I don't know where to start. The results sometimes end up with extra text that follows the function...
Here are some of the links I've read:
Regex (grep) for multi-line search needed
https://askubuntu.com/questions/551338/how-do-i-grep-for-multiple-patterns-on-multiple-lines