in reply to Conditional regex

Any one deal with this kind of situation before?
Sure. Problem with parsing HTML with Regex's

Replies are listed 'Best First'.
Re^2: Conditional regex
by Anonymous Monk on May 11, 2009 at 16:25 UTC
    The solution I discovered is this...

    $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; }
    The key I discovered was the "e" switch on the regex.