- or download this
$str =~ s/X[^X]*$/X/;
- or download this
$str =~ s/(.*X).*/$1/;
- or download this
$str =~ s/.*X\K.*//;
- or download this
$str =~ /.*X/g and $str =~ s/\G.*//;
- or download this
($str = reverse $str) =~ s/^[^X]+//;
$str = reverse $str;
- or download this
substr($str, rindex($str, "X")+1) = "";
- or download this
use Benchmark 'cmpthese';
my $str = "alphabet X alphabet" x 100 . "junk at the end" x 10;
...
capt_repl 41274/s 545% 4% -- -35% -82%
rx_rx 63380/s 891% 60% 54% -- -73%
substr 230796/s 3507% 482% 459% 264% --
- or download this
cmpthese(-5, {
last => sub { my $x = $str; $x =~ s/([A-Z])[^A-Z]*$/$1/ },
...
capt_repl 30599/s 447% -- -21% -24%
rx_rx 38948/s 597% 27% -- -3%
sexeger 40049/s 616% 31% 3% --
- or download this
/* C code */
printf("%s", strpbrk("breakfast", "aeiou"));
/* prints: eakfast */
- or download this
if ("breakfast" =~ /[aeiou]/) {
$x = substr("breakfast", $-[0]);
}
- or download this
# crindex is char-class-based rindex()
use String::Index 'crindex';
...
rx_rx 38194/s 584% 25% -- -4% -30%
sexeger 39594/s 609% 29% 4% -- -28%
crindex 54829/s 882% 79% 44% 38% --