Over a million developers have joined DZone.

Regular Expression To Match An HTML Comment

·
// 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:

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

{{ parent.tldr }}

{{ parent.urlSource.name }}