Hi All,
I am a beginer to regular expressions.
My requirement is to change / with + for the urls in html.
I dont need to do this for http:// urls though.
I wrote a peice of code, but looked to me that there should
be more efficient way to do this....Please suggest me, I will be grateful. I 've to do the appending yet though
If my original html has:
</P><HTML><B>TEST</B><P> </P><ahref="/planning/pandu/index.html">Planning</a></P><HTML><B>TEST</B><P> </P><ahref="/Home/Bank/Aboutus.html">Aboutus</a>';
I need to change it as
</P><HTML><B>TEST</B><P> </P>/some/custom/appending?planning+pandu+index.html">Planning</a></P><HTML><
B>TEST</B><P> </P>Home+Bank+Aboutus.html">Aboutus</a>
Thanks,
**************************************************
my $orightml = ' </P><HTML><B>TEST</B><P> </P><ahref="/planning/pandu/index.html">Planning</a></P><HTML><B>TEST</B><P> </P><ahref="/Home/Bank/Aboutus.html">Aboutus</a>';
$orightml =~ s/\/n//g;
my $origahref;
my $changedaref;
my $count;
my @list = split(/<ahref/,$orightml);
#print @list;
foreach(@list)
{
$count++;
if($count != 1)
{
$origahref = "<ahref".$_;
$origahref =~ m|(<ahref="
(.*)(">)(.*)|;
$ahref_begin = $1;
$ahrefend = $3;
$restofit = $4;
$url = $2;
$url=~ s|/|+|g;
$url=~ s|\+?||;
$changedaref .= $ahrefbegin.$url.$ahrefend.$restofit;
}
else
{
$changedaref = $_;
}
}
print $changedaref;
*******************************************
I am a beginer to regular expressions.
My requirement is to change / with + for the urls in html.
I dont need to do this for http:// urls though.
I wrote a peice of code, but looked to me that there should
be more efficient way to do this....Please suggest me, I will be grateful. I 've to do the appending yet though
If my original html has:
</P><HTML><B>TEST</B><P> </P><ahref="/planning/pandu/index.html">Planning</a></P><HTML><B>TEST</B><P> </P><ahref="/Home/Bank/Aboutus.html">Aboutus</a>';
I need to change it as
</P><HTML><B>TEST</B><P> </P>/some/custom/appending?planning+pandu+index.html">Planning</a></P><HTML><
B>TEST</B><P> </P>Home+Bank+Aboutus.html">Aboutus</a>
Thanks,
**************************************************
my $orightml = ' </P><HTML><B>TEST</B><P> </P><ahref="/planning/pandu/index.html">Planning</a></P><HTML><B>TEST</B><P> </P><ahref="/Home/Bank/Aboutus.html">Aboutus</a>';
$orightml =~ s/\/n//g;
my $origahref;
my $changedaref;
my $count;
my @list = split(/<ahref/,$orightml);
#print @list;
foreach(@list)
{
$count++;
if($count != 1)
{
$origahref = "<ahref".$_;
$origahref =~ m|(<ahref="
$ahref_begin = $1;
$ahrefend = $3;
$restofit = $4;
$url = $2;
$url=~ s|/|+|g;
$url=~ s|\+?||;
$changedaref .= $ahrefbegin.$url.$ahrefend.$restofit;
}
else
{
$changedaref = $_;
}
}
print $changedaref;
*******************************************