Code:
$buffer = '
//Test
var url = \'http://test.com\';
var x = \'foo\'; // test
var myregex = \'/(*)?//\'';
echo preg_replace("/(?:\/\/.*)/", "", $buffer);
Result:
var url = 'http://
var x = 'foo';
var myregex = '/(*)?`
Expected Result:
var url = 'http://test.com';
var x = 'foo';
var myregex = '/(*)?//'
Is a first step to minify JavaScript, but im don´t see solution for this.
Any suggestion?
//and everything following it from every line. Minification is not only a lot more than removing comments (eg. also reducing the size of private identifiers). For that you need to parse the language. But as it is a solved problem, why do you want to do this?.*?would be lazy, the(?: ... .*)in the code is simply a non-stored sub-pattern.uglifyjs --compress --mangle -- input.js