Removes the regular expression for the comment statement in javascript

  • 2020-03-30 03:18:57
  • OfStack


function removeJsComments(code)   
{     
    return code.replace(/(?:^|n|r)s*/*[sS]*?*/s*(?:r|n|$)/g, 'n').replace(/(?:^|n|r)s*//.*(?:r|n|$)/g, 'n');  
}

Multi-line comments:

/(?:^|n|r)s*/*[sS]*?*/s*(?:r|n|$)/g

Single line comment:

/(?:^|n|r)s*//.*(?:r|n|$)/g


Related articles: