I would like to remove comments from the source code of PHP files using Shell Script or AppleScript. (I'm using Codekit OS X App hooks)
I tried to do it with sed or grep commands, but the modern regex codes I'm used to with PHP / javascript don't work.
https://regex101.com/r/awpFe0/1/
Demo it will be enough to tell me what I want to do.
I need a working version on the command line.
I found this, but I can't get exactly the result I want: https://stackoverflow.com/a/13062682/6320082
I've been working it for two days. Please help me.
Example contents:
Test string // test comment
Test string// test comment
echo 1;//test comment
http://domain.ltd // test comment
$wrong_slashes = "http://domain.ltd/asd//asd//asd";
function test() { // test comment
Test string /* test comment // test comment */
Test string //test /* test */
Test string /* test comment /* */ */
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
/**
multi-line comments
*/
<script src="//cdn.com/site.js">
$pattern = "([//])";
$pattern = '([//])';
<!-- html comments -->
<div>test</div> <!-- html comments -->
<!-- html comments --> <div>test</div>