C doesn't have nested comments, and your code example doesn't compile (in gcc at least. Maybe you have some odd compiler). Are you trying to find the nested comments and remove them so you have compilable code? If so, you'll need to do a lot more work and probably use a parser.

For legal C comments, there is an answer in perlfaq6, " How do I use a regular expression to strip C style comments from a file", and it includes the regex from Jeffrey Friedl. If anyone has good information to add to that answer, send me the updates. :)

Good luck :)

Update: Correct perlfaq6 number, and, as ikegami notes, that FAQ deals with C comments, not nested comments. The OP said he had C source *shrug*

--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review

In reply to Re: need regex help to strip things like embedded C comments by brian_d_foy
in thread need regex help to strip things like embedded C comments by Eradicatore

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.