visual studio 2008 - REGEX to remove multiline comments -


I have a lot of searches and so far did I match the Multiline C comments:

< Pre> \ / \ * (. | \ N) * \ * \ /

but for a text like this:

  1 No Comments 2. 3.Oops No Comment / **** A Multilanguage Comment ** / Oops No Comments 4. Oops No Comment / **** A Multilanguage Comment ** / / 5. **** ** Oops is not a comment 6. *** / 7.// another comment 8. Another comment no 9. 10. "/ * Then do not leave a comment * /" 11. A line comment file result in the file looks like this: 1. a comment 2. 2. 3. There is no one comment "11.// A line comment at the end of the file  

can someone explain my mistake and let me know right? Thank you!

full code: [Speller]

 % option noyywrap% {#include & lt; stdio.h & Gt; #include & lt; stdlib.H & gt; FILE * fout;%} %% \ / \ * (. | \ N) *? \ * \ / %% void main (Int Arjak, char ** argv) {if (argc & lt; 3) {printf ( "\ N Error !!! missing command line arguments"); printf ( "\ n usage exe & lt; inputfile & gt; & lt; Output & gt; "); exit (1);} else {fout = fopen (argv [2]," w "); Yyout = fout; yyin = fopen (argv [1 ], "r"); yy Lakes ();} system ( "pause");}  

[/ spoiler]

Try adding a ? to make it non-greedy: \ / \ * (. | \ N) *? \ * \ / .

Matches:

  1. / **** A multilanguage comment ** /
  2. / * *** A multilanguage comment ** ** / 5. ** **** Oops is no comments 6. *** /
  3. / * No comment * /

If these matches are not correct, please tell us better if should match.


Comments