This shows use cases where a simple regex like the one on StackOverflow cannot be relied upon for 100% accuracy in detecting comments in code.
var foo = "There's no way to tell that this /* is not the beginning of a comment";
var bar = "There's no way to tell that this */ is not the end of a comment";
var baz = "There's no way to tell that this // is not a single line comment";
var buz = "Matters get much worse when there are escaped \" quotes /* inside the string. Definitely need a parser.";
var fiz = `And there is
really no way to // detect that these are
/* not real comments */
within a JS template literal.
`;
var foo = {
bar:// regex cannot distinguish "bar://" from "http://"
"the value for bar is dangling down here - this is valid"
};
{
include: [
"src/**/*.js
],
exclude: [
"src/**/*.test..js
]
}
If you read the SO answer in full, I am very clear about how to keep from losing the character in front of double slashes. I've been dealing with people not reading lately and it's getting frustrating. You MUST use backreference
$1
in your replacement value. If you use an empty string, you will lose every character immediately preceding a double slash.