in reply to Matching C-Style comments

Note that if, for example, you are processing C source code, then all of the methods presented so far can make mistakes. For example, using them on this:

int fun( char *string ) { // Check string/*string for validity: if( NULL != string && '\0' != *string ) { /* Okay! */ static char *punct= "!@#-+/*.,;"; /* Strip some punction characters: */ stripchars( string, punct ); ....
will strip some important stuff that isn't comments! To deal with such problems gets pretty close to writing a parser so you might want to consider Parse::RecDescent (which may even come with an example grammar that parses C).

Alternately, you can write your own parser that understands just a few things like C strings, C++-style comments, and, of course, C-style comments and work your way along. Sorry, I'm not going to try to throw a working version of that together right here, nor am I going to track one down for you (though I expect this has been written more than once so you can probably find one if you are good at searching).

I just didn't want you to get caught by surprise on this.

        - tye (but my friends call me "Tye")