#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; my @strings = qw( He_is_super_hero_Spiderman He_was_a_super_actor_Tom ); for my $string (@strings) { my ($spiderman_or_tom) = $string =~ /Spiderman|Tom/g; say $spiderman_or_tom; my ($last_word) = (split /_/, $string)[-1]; say $last_word; my ($last_capitalized) = $string =~ /.*([[:upper:]][^_]+)/; say $last_capitalized; }
Update: Explanation of the second solution: negative indices count from the right.
Explanation of the third solution: .* matches as much as it can, then it captures the word starting with an uppercase letter and continuing with anything but underscore.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
In reply to Re: Pattern for a single word
by choroba
in thread Pattern for a single word
by Nansh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |