I have a javascript file with deeply needed comments. Javascript uses C style comments:
//this is a single line comment
And
/* this is
a multi-line
comment */
However, the actual code looks closer to this:
/* blah blah
// [NOTE] blah blah
// blah
// blah blah blah
// blah
// blah blah
function("string", false);
// 1: blah blah blah blah blah blah
// [1] https://example.com
function("string", true);
/* blah blah
* blah blah //* /
function("string", false);
// * * * /
// 18: blah blah blah blah blah blah
// [-] (part1) https://example.org/43
function("string", 0);
// * * * /
// 20: blah blah blah blah blah blah
// [NOTE] blah blah blah blah blah blah blah blah blah blah blah blah
// [-] https://example.org/62015
function("some_string", "string"); // (comment)
// 0301: blah blah blah blah blah blah
// [-] https://example.org/205
// function("string", false);
// 040: blah blah blah blah blah blah
// What is this?
// [-] https://example.org/58917
function("string", true);
// 050: blah blah blah blah blah blah
// [-] https://example.org/57226
function("string", false);
// 103: blah blah blah blah blah blah
// [-] https://example.org/53751
// function("string", false);
// 203: blah blah blah blah blah blah
// [WARNING] This may break
// [-] https://example.org/70082
function("string", false);
// 27: blah blah blah blah blah blah
// [-] https://example.org/57170
// function("string", 90); // default: 90
// 55: blah blah blah blah blah blah
// [-] https://example.org/73595
// function("string", true);
// * * * /
// ***/
function("string", 99); //comment comment
The answers I found, like this one, deal with simpler situations.
shell script - How can I remove all comments from a file? - Unix & Linux Stack Exchange How can I remove all comments from a file?
The main problem I experienced was that my various regex were too greedy, for example, selecting everything from the very first /*
to the very last */
. I did not try Perl because I'm not familiar with it. And, unfortunately, the tools I did try did not have support for all the regex syntax I would have wanted to try. I'm not sure which simple tool is best suited for this task.
function("string //")
. – Kaz Dec 16 '18 at 17:07