mirror of
https://github.com/perlbot/perlbuut
synced 2025-06-07 19:05:50 -04:00
adding the global code, i hope it works right
This commit is contained in:
parent
7ece8e935a
commit
2936924a37
1 changed files with 15 additions and 1 deletions
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue