0

i need to make a program where the input file is a source code with comments and output is the same code without comments.

It would be perfect if it would eliminate the /* */ comments also.

Marko Paju
  • 314
  • 1
  • 13

1 Answers1

-1

to solve your problem you'll have to user preg_replace

    $notCommentedFile = preg_replace('/#.*/', '', $commentedFile);
    $notCommentedFile = preg_replace('#//.*#', '', $notCommentedFile);
    $notCommentedFile = preg_replace('#/\*(?:[^*]*(?:\*(?!/))*)*\*/#', '', $notCommentedFile);

this 3 pattern will remove the comment on your file ^^

UPDATE

ups! didn't see the comment X/ this works for php, but i think a java function like preg_replace exist and regular expression are universal :D

here an example on how to use the equivalent preg_replace in java What is the Java equivalent to this preg_replace?

Community
  • 1
  • 1
Aliceiw
  • 420
  • 5
  • 19