SPUG: regular expressions

Ken Clarke kenslinux at shaw.ca
Tue Jan 17 14:31:46 PST 2006


To identify the beginning of a word, match on the beginning of the string or 
a space character, followed by a letter.  Also might as well only match on a 
lower case letter since that's all you want to change.

$sentence =~ s/(^|\s)([a-z])/$1\U$2/g;

----- Original Message ----- 
From: "Randy Rue" <rrue at fhcrc.org>
To: <spug-list at pm.org>
Sent: Tuesday, January 17, 2006 2:07 PM
Subject: Re: SPUG: regular expressions


> Bear with me for a newbie question, I'm right at the second regex
> chapeter in Learning Pearl and this question caught my attention:
>
> What does the (\w) in the pattern do to the \b word separator? I thought
> it might give whitespace as the word delimiter (and so keep words like
> "that's" as a single word) but the output still comes out as "That'S."
>
> How else could I treat contractions?
>
> Randy Rue
>
> Jeremy Mates wrote:
>> * luis medrano <lmzaldivar at gmail.com>
>>
>>>perl is number one
>>>to
>>>Perl Is Number One
>>
>>
>> Quick, dirty, and possibly missing all sorts of edge cases:
>>
>> echo test ing | perl -pe 's/\b(\w)/\U$1/g'
>>
>> Depending on what you are doing, also consider {case => title} or {case
>> => highlight} of the nifty Text::Autoformat module.
>>
>> http://search.cpan.org/perldoc/Text::Autoformat
>>
>> _____________________________________________________________
>> Seattle Perl Users Group Mailing List
>>      POST TO: spug-list at pm.org
>> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
>>     MEETINGS: 3rd Tuesdays
>>     WEB PAGE: http://seattleperl.org/
>
> -- 
> Randall Rue
> System Administrator
> IT, Server Operations
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave N #J4-414
> Seattle, WA 98109-1024
> USA
> (206) 667-3662
> FAX (206) 667-7733
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
>     POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
>    MEETINGS: 3rd Tuesdays
>    WEB PAGE: http://seattleperl.org/ 



More information about the spug-list mailing list