How can I strip multiline C comments from a file using Perl?

前端 未结 6 1153
情话喂你
情话喂你 2020-12-03 04:02

Can anyone get me with the regular expression to strip multiline comments and single line comments in a file?

eg:

                  \" WHOLE         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 04:51

    Remove /* */ comments (including multi-line)

    s/\/\*.*?\*\///gs
    

    I post this because it is simple, however I believe it will trip up on embedded comments like

    /* sdafsdfsdf /*sda asd*/ asdsdf */
    

    But as they are fairly uncommon I prefer the simple regex.

提交回复
热议问题