Using a parser can take a lot of the pain out of it. However much "confusion" there is in the html (and there is a lot of it about!) this snippet may help ease the way.
output:#!/bin/perl5 use strict; use warnings; use HTML::TokeParser::Simple; my $p = HTML::TokeParser::Simple->new(\*DATA); my $http = q{http://domain.com}; while (my $t = $p->get_token){ if ( $t->is_start_tag(q{img}) and $t->get_attr(q{src}) ) { my $src = $t->get_attr(q{src}); if ($src !~ m|^http://|){ $src = join '/', $http, $src; $t->set_attr(src => $src); } } print $t->as_is; } __DATA__ <img src="pics/local.jpg" alt="" /> <img src="http://remote.com/pics/remote.jpg" /> more confusion, just in case: 3:00pm 12/12/12 other urls <a href="http://fake.com"> http://fake.com</a>
<img src="http://domain.com/pics/local.jpg" alt="" /> <img src="http://remote.com/pics/remote.jpg" /> more confusion, just in case: 3:00pm 12/12/12 other urls <a href="http://fake.com"> http://fake.com</a>
In reply to Re: Find and replace with regex
by wfsp
in thread Find and replace with regex
by JayBee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |