Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Regular Expression To Match An HTML Comment

DZone's Guide to

Regular Expression To Match An HTML Comment

·
Free Resource
// description of your code here
This snippet uses the non-greedy matcher, and the "m" option to treat strings as multi-lines, so it may not work with all regex parsers.


/\
  )/m

Examples in Ruby IRB:
irb(main):029:0> html = <<-EOL
irb(main):030:0" 
   Second Comment 
  
irb(main):033:0" EOL
=> "
   Second Comment 
  \n"
irb(main):075:0> m = html.match(/\
  )/m)
=> #
  
   
irb(main):076:0> m[0]
=> "
   "
irb(main):077:0> m[1]
=> "  First  Comment   --\n      "


  
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}