I know variations of this question have been asked many times, but none of the other solutions I've found have worked for me.
I'm simply attempting to come up with a regex to remove any single line comments that may appear in some javascript.
Ideally, it would have some way to check that two forward slashes aren't part of any actual script.
$("a[href='#top']").click(function() { // This should be removed
$('html, body').animate({
scrollTop:0
}, 'slow');
return false;
});
var SomeURL = 'http://www.google.com'; // This comment should be removed but the URL should not
I have this:
$fileContents = preg_replace('/\/\/.*/', '', $fileContents);
...but that breaks my code because it strips out URL's along with single line comments