my $regex = qr{href\s*=\s*".*?"};
####
use strict;
use warnings; # this is also useful
my $regex = qr{href\s*=\s*".*?"};
my $sub = "href=\"#\"";
while(){
s/$regex/$sub/g;
print;
}
__DATA__
afjalsdfj href="asfasdfa" afdsas href="akjshfakjsd"
href = "ajsfhaklj"
##
##
use strict;
use warnings;
use HTML::Parser;
use HTML::Entities;
my $html = join '', ;
my $p = HTML::Parser->new(
default_h => [ sub { print shift }, 'text' ],
comment_h => [""],
start_h => [ \&start, 'tag,attr,attrseq,text' ]
);
$p->parse($html);
sub start {
my ( $tag, $attr, $attrseq, $text ) = @_;
unless ( exists $attr->{href} ) {
print $text;
}
else {
$attr->{href} = "#";
print "<$tag";
print " $_=\"", encode_entities( $attr->{$_} ), '"' for (@$attrseq);
print ">";
}
}
__DATA__
title
link
some text and more