Permalink
Browse files

When removing /* */ style comments from the config file, use a non-gr…

…eedy regex.
  • Loading branch information...
1 parent 506f2c7 commit 82f5d45a8d2666327b5f4cdcc5f676bd82cd081c @aag aag committed May 17, 2012
Showing with 9 additions and 1 deletion.
  1. +9 −1 lib/cli.js
View
@@ -10,7 +10,15 @@ function existsSync() {
function _removeJsComments(str) {
str = str || '';
- str = str.replace(/\/\*[\s\S]*(?:\*\/)/g, ''); //everything between "/* */"
+
+ // replace everything between "/* */" in a non-greedy way
+ // The English version of the regex is:
+ // match '/*'
+ // then match 0 or more instances of any character (including newlines)
+ // except for instances of '*/'
+ // then match '*/'
+ str = str.replace(/\/\*(?:(?!\*\/)[\s\S])*\*\//g, '');
+
str = str.replace(/\/\/[^\n\r]*/g, ''); //everything after "//"
return str;
}

0 comments on commit 82f5d45

Please sign in to comment.