JSFiddle - React, Tailwind, and code Playground

JavaScript

var s = `before
/* first line of comment
   second line of comment */
   -- remove this comment too
after
`;
var stringWithoutComments = s.replace(/(\/\*[^*]*\*\/)|(\/\/[^*]*)|(--[^*]*)/g, '');
/*
Expected:

before

after
*/
console.log(stringWithoutComments);