in reply to Re^2: Find First character of each word in a string
in thread Find First character of each word in a string
If that's the way things are, then maybe:
>perl -wMstrict -le "my $str = 'eternal corruption defilement'; ;; $str =~ s{ \b ([[:alpha:]]) [[:lower:]]* \s* }{\U$1}xmsg; ;; print qq{'$str'}; " 'ECD'
Update: Removed an unnecessary level of capture grouping in regex above. Also: [[:lower:]]* might be better as [[:alpha:]]* instead.
Update: Or even:
>perl -wMstrict -le "my $str = 'eternal corruption defilement'; ;; $str =~ s{ (\b [[:alpha:]]+ \s*) }{ uc substr $1, 0, 1 }xmsge; ;; print qq{'$str'}; " 'ECD'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Find First character of each word in a string
by kevyt (Scribe) on Nov 24, 2010 at 01:19 UTC |