<p>
文字列(テスト用)があり、divの下のすべてのインスタンスを置き換えたい<div id="text">
. それ、どうやったら出来るの ?
m
修飾子と修飾子でテストしましs
たが、無駄でした (最初のものだけが置き換えられます)。以下にPerlコードを示します。
#!/usr/bin/perl
use strict;
use warnings;
my $string = <<STRING;
<div id="main">
hellohello
<div id="text">
nokay.
<p>This is p1, SHUD B replaced</p>
Alright
<p>This is p2, SHUD B replaced</p>
Yes 2
<p>this is P3, SHUD B replaced</p>
Okay done
bye
</div>
bye
<p>this is not under the div whose id is text and SHUDN'T b replaced</p>
</div>
STRING
my $str_bak = $string;
print "Sring is : \n$string\n\n";
$string =~ s/(<div id="text">.*?)<p>(.*)(<\/p>.*?<\/div>)/$1<p style="text-align:left;">$2 $3/sig;
print "Sring now is : \n$string\n\n";