views:

50

answers:

4

What I like to do is remove all functions which has specific word for example, if the word is 'apple':

void eatapple()
{
// blah
// blah
}

I'd like to delete all code from 'void' to '}'. What I tried is:

^void.*apple(.|\n)*}

But it took very long time I think something is wrong here.

I'm using Visual Studio. Thank you.

A: 
Welbog
@Welbog, I don't think counting braces is an easy program to write. If it has to be error free, the program must be capable of understanding the source just like the compiler.
Codism
@Codism: Counting braces is simple. You just have to watch out for gotchas like braces within comments and string literals. You're right that in order to be error-free you need to write a context-free parser for it, but that is the level of complexity of this task. A brace counter should be fine as long as there are no gotchas.
Welbog
A: 

In theory, regular language is not able to express a sentence described by context free grammar. If it is a one time job, why don't you just do it manually.

Codism
A: 

Switch to VI. Then you can select the opening brace and press d% to delete the section.

Seth Johnson
I love VI. but I didn't know that one. thanks
Jace Jung
The percent sign moves to matching braces, brackets, and parentheses.
Seth Johnson
A: 

Finally did it.

^void.\*{apple|Apple}\(\)\n\{\n{(\t.\*\n)|(^$\n)}*^\}
Jace Jung