Leser: 22
$mod_textformator_text =~ s/(\[img\])([a-zA-Z0-9+-_.\/:]*?)(\[\/img\])/<img src="$2">/g;
1 2 3 4 5 6 7
$maxcount = 2; #replace anzahl $count = 0; #anfang while($count < $maxcount) { $mod_textformator_text =~ s/(\[img\])([a-zA-Z0-9+-_.\/:]*?)(\[\/img\])/<img src="$2">/; $count=$count + 1; }
1 2 3 4 5 6 7 8
$s = "foo img123 bar img456 baz img789 boo"; my $c = 0; my $max = 2; $s =~ s/(img)(\d+)/++$c > $max ? "$1$2" : qq{<img src="$2">}/eg; print $s; __END__ Ausgabe: foo <img src="123"> bar <img src="456"> baz img789 boo
1 2 3 4 5 6 7 8
my $counter=5; while($mod_textformator_text =~ s/(\[img\])([a-zA-Z0-9+-_.\/:]*?)(\[\/img\])/<img src="$2">/) { $counter--; last if($counter==0) } print "$counter mal Ersetzt.\n";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/usr/bin/perl -l use strict; use warnings; my $str = 'aaaa5aaaa0'; my $cnt = 7; for my $i ( 1 .. $cnt ) { # ersetze oder Abbruch, wenn keine Ersetzung (mehr) moeglich $str =~ s/a/X/ || last; print $i; } print $str;
my $count = ($wert =~ tr/[0-9]//c);