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);
Javascript ( " " ), JSMin Douglas Crockford? # (http://www.crockford.com/javascript/jsmin.cs)
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.
Regex YUI Compressor . Net, JavaScript.
// Note: string javaScript == some javascript data loaded from some file, etc. compressedJavaScript= JavaScriptCompressor.Compress(javaScript);
stripcmt:
StripCmt - , C, C, ++, Java. Unix , FIFO ( - ) .
Simple and reliable, does the job flawlessly.
content = Regex.Replace(content, "/\\*.*?\\*/", String.Empty, RegexOptions.Compiled | RegexOptions.Singleline);