in reply to Re: Conditional regex
in thread Conditional regex
The key I discovered was the "e" switch on the regex.$contents =~ s/(<IMG\s.*?>)/&addalt($1)/sige; $contents =~ s!\>alt=\"\"! alt=\"\"\>!sig; print $contents; sub addalt { my $returned=shift; if ($returned!~m/\salt/){ $returned=$returned.'alt=""'; } return $returned; }
|
---|