[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Regex to remove whitespace and to capitalize



Tim Ayers wrote:
> So I tried
> 
>   $x =~ s/(^.)|[\s_]+(\S)/\U\1/g;
> 
> but that didn't work. For example, 'Hi there' goes to 'Hihere'. I was
> surprised by the loss of the 't'. I would have more expected
> 'HiHhere'. What's going on?

in the second substitution, ' t' matches '[\s_]+(\S)',
and $2 (-not- $1) gets set to 't'.  $1 is ''.  that's
what happened to the 't'.
--
Steve Lane <sml@zfx.com>

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe