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:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}