0

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

A regular expression to exclude a word/string

Community
  • 1
  • 1
Otto Nahmee
  • 133
  • 1
  • 2
  • 13
  • #1 your negative lookahead should have some flexibility in it: `(?!(?i).*something)`. #2 you cannot do with regular expressions – glenn jackman May 20 '15 at 01:17
  • @glennjackman Thanks I've tried `grep -IPzor 'void.*myfunction(\n|.)*\{(\n|.)*(?!(?i).*Something|something)(\n|.)*\}' ./*` but it didn't seem to work. I suppose I don't know what `?i` does? – Otto Nahmee May 21 '15 at 22:34
  • `perldoc perlre` -- it is a case insensitivity flag within a RE – glenn jackman May 22 '15 at 01:02

0 Answers0