PDA

View Full Version : Perl regex question


Afrow UK
03-17-2004, 04:31 PM
Here's a likely simple question...

I want to replace a word with another word in a string, but if the word is between <a and </a>, then do not replace it.

Edit: The current code:

%word_desc = (
"stats logger" => "A program by Afrow UK for creating D-Day player statistics",
"inland campaign" => "A D-Day\: Normandy campaign by Perez\, Darwin\, Fafner\, &amp; H-Hour",
"ammoware" => "Afrow UK\\'s upcoming D-Day\: Normandy map",
"ammunitions warehouse" => "Afrow UK\\'s upcoming D-Day\: Normandy map",
"map-compiler" => "A program by Afrow UK for compiling Quake II levels",
);

sub word_descriptions {
my $input = shift;
foreach (keys %word_desc) {
$input =~ s|($_)|<span style="color\: \#FF9900" onmouseover="window\.status=\(\'$1\: $word_desc{$_}\.\'\)" onmouseout="window\.status=\'\'">$1</span>|i;
}
return $input;
}


I cannot find a way to do this.

Cheers

-Stu

hitesh29
04-07-2004, 06:18 AM
sub word_descriptions {
my $input=shift;

foreach (keys %word_desc) {
$input =~ s|($_)|\<span style=\"color\: \#FF9900\" onmouseover=\"window\.status=\(\'$1\: $word_desc{$_}\.\'\)\" onmouseout=\"window\.status=\'\'\">$1</span>|i;
}
return $input;
}

try out this one.