Over a million developers have joined DZone.

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.


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


Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}