I'm adding some minification to our cache.class.php and am running into an edge case that is causing me grief.
I want to remove all comments of the // variety, HOWEVER I don't want to remove URLs...
Given some example text here with carefully crafted cases:
// another comment here
if (window.sidebar) // firefox
window.sidebar.addPanel(title, url, "");
else if(window.opera &
else if(document.all)// ie
I've tried so many variations and hunted on StackOverflow, Google, etc. and what would seem like a task already solved, doesn't seem to be.
This is "close", but still matches //foo.com (omitting the : of course)
s*(?!:)//.*?$ (count it as '/m' multiline)
This ultimately ends up in a PHP line of code like so:
$sBlob = preg_replace("@s*//.*?$@m",'',$sBlob);
Here are some other links of stuff I've found and tried to experiment with varying degrees.