# Help on html content modification

**URL:** <https://www.ruby-forum.com/t/help-on-html-content-modification/183467>\
**Category:** Rails\
**Created:** [February 15, 2010, 6:33am UTC](https://www.ruby-forum.com/t/help-on-html-content-modification/183467 "2010-02-15T06:33:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [February 15, 2010, 6:33am UTC](https://www.ruby-forum.com/t/help-on-html-content-modification/183467/1 "2010-02-15T06:33:33Z")

</div>

Dear all,

i have a html file in my local path.

In that html file i have below tag.

![](https://www.ruby-forum.com/2010-01-12/Capture/1210420100112145725141.jpg)

Now what i need is i want to modify the above tag into

![](https://www.ruby-forum.com/Capture/1210420100112145725141.jpg)

i want to replace all the image path like above path.

Is it possible to do? i have a idea in hpricot parser.

Is it worth to try with hpricot…

if so,kindly provide any sample code or links

Thank you for your time

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [February 15, 2010, 6:55pm UTC](https://www.ruby-forum.com/t/help-on-html-content-modification/183467/2 "2010-02-15T18:55:05Z")

</div>

Here’s a hpricot example that works:

require ‘rubygems’  
require ‘hpricot’

doc = Hpricot(“

\<img  
src="/2010-01-12/Capture/1210420100112145725141.jpg"  
/\>

”)

doc.search(‘img’).each do |img|  
img[‘src’] = img[‘src’].gsub(/^/\d{4}-\d{2}-\d{2}/, “”) # have to do  
gsub  
â€“ gsub! doesn’t work  
end

puts doc.html

Anyone, if this can be done smarter, please write.

–Lasse

2010/2/15 Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
