ruby - How do I remove HTML encoded characters from a string? -



ruby - How do I remove HTML encoded characters from a string? -

i have string contains html encoded characters , want remove them:

"<div>hi all,</div><div class=\"paragraph_break\">< /></div><div>starting today initiating pols.</div><div class=\"paragraph_break\"><br /></div><div>please utilize next communication protocols:<br /></div><div>1. task breakup , allocation - gravity<br /></div><div>2. mail service communications - bc messages<br /></div><div>3. reports on poc / spikes: writeboard<br /></div><div>4. non story related tasks: bc to-do<br /></div><div>5. ui , html communicated through bc.<br /></div><div>6. file sharing, we'll using dropbox.<br /></div><div>7. utilize skype lighter , generic desicussions. however, in case need approvals, info later reference, etc, please utilize bc. pols conversation has been created on skype.</div><div class=\"paragraph_break\"><br /></div><div>you'll have been given necessary accesses these portals. please start using them judiciously.</div><div class=\"paragraph_break\"><br /></div><div>all best!</div><div class=\"paragraph_break\"><br /></div><div>thanks,<br /></div><div>saurav<br /></div>"

what want doable many ways. perhaps looking @ why might want help. when want remove encoded html, want recover contents of html. ruby has modules create easy.

require 'cgi' require 'nokogiri' html = "<div>hi all,</div><div class=\"paragraph_break\">< /></div><div>starting today initiating pols.</div><div class=\"paragraph_break\"><br /></div><div>please utilize next communication protocols:<br /></div><div>1. task breakup , allocation - gravity<br /></div><div>2. mail service communications - bc messages<br /></div><div>3. reports on poc / spikes: writeboard<br /></div><div>4. non story related tasks: bc to-do<br /></div><div>5. ui , html communicated through bc.<br /></div><div>6. file sharing, we'll using dropbox.<br /></div><div>7. utilize skype lighter , generic desicussions. however, in case need approvals, info later reference, etc, please utilize bc. pols conversation has been created on skype.</div><div class=\"paragraph_break\"><br /></div><div>you'll have been given necessary accesses these portals. please start using them judiciously.</div><div class=\"paragraph_break\"><br /></div><div>all best!</div><div class=\"paragraph_break\"><br /></div><div>thanks,<br /></div><div>saurav<br /></div>" puts cgi.unescapehtml(html)

which outputs:

<div>hi all,</div><div class="paragraph_break">< /></div><div>starting today initiating pols.</div><div class="paragraph_break"><br /></div><div>please utilize next communication protocols:<br /></div><div>1. task breakup , allocation - gravity<br /></div><div>2. mail service communications - bc messages<br /></div><div>3. reports on poc / spikes: writeboard<br /></div><div>4. non story related tasks: bc to-do<br /></div><div>5. ui , html communicated through bc.<br /></div><div>6. file sharing, we'll using dropbox.<br /></div><div>7. utilize skype lighter , generic desicussions. however, in case need approvals, info later reference, etc, please utilize bc. pols conversation has been created on skype.</div><div class="paragraph_break"><br /></div><div>you'll have been given necessary accesses these portals. please start using them judiciously.</div><div class="paragraph_break"><br /></div><div>all best!</div><div class="paragraph_break"><br /></div><div>thanks,<br /></div><div>saurav<br /></div>

if want take step farther , remove tags, retrieving text:

puts nokogiri::html(cgi.unescapehtml(html)).content

will output:

hi all,starting today initiating pols.please utilize next communication protocols:1. task breakup , allocation - gravity2. mail service communications - bc messages3. reports on poc / spikes: writeboard4. non story related tasks: bc to-do5. ui , html communicated through bc.6. file sharing, we'll using dropbox.7. utilize skype lighter , generic desicussions. however, in case need approvals, info later reference, etc, please utilize bc. pols conversation has been created on skype.you'll have been given necessary accesses these portals. please start using them judiciously.all best!thanks,saurav

which want when see sort of string.

ruby's cgi makes encoding , decoding html easy. nokogiri gem makes easy remove tags.

ruby string html-parsing

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -