Created
October 20, 2011 13:33
-
-
Save orangexception/1301150 to your computer and use it in GitHub Desktop.
Revisions
-
orangexception revised this gist
Oct 20, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ This regular expression was designed to minify simple JavaScript. I put spaces in square brackets as a reminder that they exist. Spaces can be important. For example, `$( "#foo #bar" )` should not become `$("#foo#bar")`. However, we do want to remove spaces if they are used for indentation. I'm having trouble removing // comments due to values such as "http://." I'm having some success with `(?s)(?m)[\t\r\n]|[ ][ ]+|/\*.*?\*/|^//[^\r\n]*|[^\\"":]//[^\r\n]*`, but I need to build more test cases. # Usage in ColdFusion `sJavaScriptContent= sJavaScriptContent.ReplaceAll( "(?s)[\t\r\n]|[ ][ ]+|/\*.*?\*/**" , "" );` -
orangexception revised this gist
Oct 20, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ I put spaces in square brackets as a reminder that they exist. Spaces can be imp I'm having trouble removing // comments due to values such as "http://." # Usage in ColdFusion `sJavaScriptContent= sJavaScriptContent.ReplaceAll( "(?s)[\t\r\n]|[ ][ ]+|/\*.*?\*/**" , "" );` # Test Cases ``` -
orangexception revised this gist
Oct 20, 2011 . 1 changed file with 13 additions and 32 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,16 @@ # Notice Do not run this against minified JavaScript packages. The minified packages often rely on line returns to execute correctly. This regular expression was designed to minify simple JavaScript. # Regular Expression `(?s)[\t\r\n]|[ ][ ]+|/\*.*?\*/*` I put spaces in square brackets as a reminder that they exist. Spaces can be important. For example, `$( "#foo #bar" )` should not become `$("#foo#bar")`. However, we do want to remove spaces if they are used for indentation. I'm having trouble removing // comments due to values such as "http://." # Usage in ColdFusion `sJavaScriptContent= sJavaScriptContent.ReplaceAll( "(?s)\s|/\*.*?\*/|//[^\r\n]*" , "" );` # Test Cases @@ -25,33 +32,7 @@ test 3 */ // ////// Test 9 // */ Test 10 $( "#foo #bar" ).val( "Test 11 - This value should exist." ); $( "#foo #bar" ).val( "http://orangexception.com/" ); // Test 12 - http:// should exist. However, this comment should not exist. // // Test 13 - This line should be gone. http://orangexception.com/foo/bar/ ``` -
orangexception revised this gist
Oct 20, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ # Usage in ColdFusion I've tested with ColdFusion 8 and Railo 3.3. `sJavaScriptContent= sJavaScriptContent.ReplaceAll( "(?s)\s|/\*.*?\*/|//[^\r\n]*" , "" );` # Test Cases ``` -
orangexception created this gist
Oct 20, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ # Regular Expression `(?s)\s|/\*.*?\*/|//[^\r\n]*` # Usage in ColdFusion I've tested with ColdFusion 8 and Railo 3.3. sJavaScriptContent= sJavaScriptContent.ReplaceAll( "(?s)\s|/\*.*?\*/|//[^\r\n]*" , "" ); # Test Cases ``` // Test 0 /* Test 1 */ /* Test * / * 2 */ /* Test . test . test test 3 */ /* Test * / * 4 */ /* Test 5 *//**/ /* Test 6 /*/ // Test 7 /* Test // 8 */ // ////// Test 9 // */ Test 10 ``` ## Complete Test ``` <cfsavecontent variable= "sJavaScriptContent"> // Test 0 /* Test 1 */ /* Test * / * 2 */ /* Test . test . test test 3 */ /* Test * / * 4 */ /* Test 5 *//**/ /* Test 6 /*/ // Test 7 /* Test // 8 */ // ////// Test 9 // */ Test 10 alert( 'end-of-line' ); </cfsavecontent> <cfset sJavaScriptContent= sJavaScriptContent.ReplaceAll( "(?s)\s|/\*.*?\*/|//[^\r\n]*" , "" ) /> <script> <cfoutput>#sJavaScriptContent#</cfoutput> </script> ```