0

I need to remove all JS ad Html comments (inline + multi line)

So far, I’ve found this:

/(\/\*[\w\'\s\r\n\*]*\*\/)|(\/\/[\w\s\']*)|(\<![\-\-\s\w\>\/]*\>)/

I could able to match almost every comments but except this kind of comment

<!-- Google Tag Manager (noscript) --> 

I’m bit doubt about inside brackets. Any idea about how to efficently achieve this.

Thanks in advance.

raslan
  • 96
  • 6
  • Posted Answers are really helpful. Foremost Thanks guys. But my use-case Is like finding all sort of comments at once. It seems I need to match this one separately. If there is any possible way like updating my regex it would be great (I’m just a regx beginner ). Content is bit large and lots of iterations are there to run. Thanks – raslan Dec 07 '18 at 07:54

1 Answers1

0

Try this regex pattern

(?=<!--)([\s\S]*?)-->

It matches html comments like these:

<!-- Google Tag Manager (noscript) --> 

or

<!--
multi line 
html comment

-->

or

<!-- single line html comment -->

Test it with https://regex101.com/r/pPnygp/1

UI_Dev
  • 3,317
  • 16
  • 46
  • 92