my $str = "<SampleElement oldattribs=\"sa1 sa2 sa3\">";
$str =~ s#<SampleElement[^>]*oldattribs="([^"]*)"#
my $fulcnt=$&;
my $afids=$1;
my @affs =();
if($afids =~ m/\s+/) {
@affs = split /\s/, $afids;
my $jnafs = join ",", map { $_=~s/[a-z]*//i, } @affs;
($fulcnt." newattribs=\"$jnafs\"");
}
else {
($fulcnt);
}
#eg;
私の出力を作成するためのPerlを使用してマップ:が参加し、分割して、新しいはattribsに
<SampleElement oldattribs="sa1 sa2 sa3" newattribs="1,1,1">
予想される出力を:私が間違っているのどこ
<SampleElement oldattribs="sa1 sa2 sa3" newattribs="1,2,3">
誰かが私を指摘することができます。前もって感謝します。
[XML/HTML](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454)を次のように解析しないでください。代わりに[XML](http://search.cpan.org/~mirod/XML-Twig/Twig.pm)パーサーを使用してください。 – dgw
ワンライナー:[ '$ STR =〜S {] * oldattribs = "\ K(? [^"] +)} [ "の$ + {V} \" newattribs = \」 " $ + {v} =〜s!\ pL *(? \ d +)$ | \ pL *(?
\ d +)\ s *! $ + {f}? $ + {f}:$ + {s}。 "、"!egr] e; '](https://ideone.com/KwEapL)。 –