# Regex to replace href links from static html

**URL:** <https://www.ruby-forum.com/t/regex-to-replace-href-links-from-static-html/186922>\
**Category:** Rails\
**Created:** [April 14, 2010, 12:58pm UTC](https://www.ruby-forum.com/t/regex-to-replace-href-links-from-static-html/186922 "2010-04-14T12:58:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![amalasingh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@amalasingh](https://www.ruby-forum.com/u/amalasingh)\
**Post date:** [April 14, 2010, 12:58pm UTC](https://www.ruby-forum.com/t/regex-to-replace-href-links-from-static-html/186922/1 "2010-04-14T12:58:08Z")

</div>

Hi,  
I am in the process of migrating some static html pages to ROR . See  
[http://pm.tamil.net/akaram\_uni.html](http://pm.tamil.net/akaram_uni.html).  
Currently it is difficult to migrate because the href references point  
to different locations.  
Eg.[http://www.tamil.net/projectmadurai/pub/pm0027/pm0027.pdf](http://www.tamil.net/projectmadurai/pub/pm0027/pm0027.pdf)  
[http://www.tamil.net/projectmadurai/pub/pm0241/pm0241.pdf](http://www.tamil.net/projectmadurai/pub/pm0241/pm0241.pdf)  
I want to move the .pdf files to one location and point the href  
references to one location.  
Please note that this is one such .html. I got loads of .html files  
similarly each href locations are pointing to different locations.  
Please provide me a regex expression to find and replace all such  
locations.

Cheers  
Amala S.  
Telford UK

---

<div class="post-metadata">

**Author:** ![amalasingh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@amalasingh](https://www.ruby-forum.com/u/amalasingh)\
**Post date:** [April 14, 2010, 12:59pm UTC](https://www.ruby-forum.com/t/regex-to-replace-href-links-from-static-html/186922/2 "2010-04-14T12:59:19Z")

</div>

On Apr 13, 9:22 pm, amalasingh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,  
> I am in the process of migrating some static html pages to ROR . Seehttp://pm.tamil.net/akaram\_uni.html.  
> Currently it is difficult to migrate because the href references point  
> to different locations.  
> Eg.[http://www.tamil.net/projectmadurai/pub/pm0027/pm0027.pdfhttp://www.tamil.net/projectmadurai/pub/pm0241/pm0241.pdf](http://www.tamil.net/projectmadurai/pub/pm0027/pm0027.pdfhttp://www.tamil.net/projectmadurai/pub/pm0241/pm0241.pdf)  
> I want to move the .pdf files to one location and point the href  
> references to one location.

You really don’t want to use a regex to parse html - you’ll end up in  
a world of pain. Use an actual html parser like Nokogiri

Fred
