Remove JavaScript comments from c # string

I'm trying to remove the javascript comments ( //and /**/) from the sting with C #. Someone has RegEx for this. I read a list of javascript files, then add them to a line and try to clear the javascript code and make the light load. Below you will find one of RegEx that works fine with comments /* */, but I also need to remove the comments //:

content = System.Text.RegularExpressions.Regex.Replace(content,
    @"/\*[^/]*/", 
    string.Empty);
+3
source share
5 answers

JS - , . , , , :

alert('string\' // not-a-comment '); // comment /* not-a-nested-comment
alert('not-a-comment'); // comment */* still-a-comment
alert('not-a-comment'); /* alert('commented-out-code');
// still-a-comment */ alert('not-a-comment');
var re= /\/* not-a-comment */; //* comment
var e4x= <x>// not-a-comment</x>;

, , "*/", "/", or // . , , JavaScript [X] HTML.

+7

Regex YUI Compressor . Net, JavaScript.

// Note: string javaScript == some javascript data loaded from some file, etc.
compressedJavaScript= JavaScriptCompressor.Compress(javaScript); 
+5

stripcmt:

StripCmt - , C, C, ++, Java. Unix , FIFO ( - ) .

Simple and reliable, does the job flawlessly.

0
source
content = Regex.Replace(content,
                        "/\\*.*?\\*/",
                        String.Empty,
                        RegexOptions.Compiled | RegexOptions.Singleline);
0
source

All Articles