From 2936924a37fa5dc294872003f214802f67b7a827 Mon Sep 17 00:00:00 2001 From: Ryan Voots Date: Fri, 12 Mar 2010 16:28:54 -0500 Subject: [PATCH] adding the global code, i hope it works right --- plugins/factoids.pm | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/factoids.pm b/plugins/factoids.pm index 4414c47..6b8c57c 100644 --- a/plugins/factoids.pm +++ b/plugins/factoids.pm @@ -334,7 +334,21 @@ sub _fact_substitute if ($flags =~ /g/) { - return "Global replacements not coded yet" + my $regex = $flags=~/i/ ? qr/(?i:$match)/i : qr/$match/; + + while ($pred =~ /\G$regex/g) + { + my $matchedstring = substr($pred, $-[0], $+[0] - $-[0]); + my ($matchstart, $matchend) = ($-[0], $+[0]); + my @caps = map {substr($pred, $-[$_], $+[$_] - $-[$_])} 1..$#+; + my $realsubst = $subst; + $realsubst =~ s/\$(\d+)/$caps[$1-1]/eg; + + substr $pred, $matchstart, $matchend-$matchstart, $realsubst; + pos $pred = $matchstart+length($realsubst); #set the new position, might have an off by one? + } + + return "$pred"; } else {