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")

In reply to (tye)Re: Matching C-Style comments by tye
in thread Matching C-Style comments by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.