Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Probably a dumb s/// question.

7 views
Skip to first unread message

Mark Healey

unread,
Mar 16, 2005, 11:14:48 AM3/16/05
to
I'm trying to craft a search that capitalizes letters depending on their
context, specifically after a space or the beginning of a string.

For example I'd like to turn

the quick brown fox jumped over the lazy dogs.

to

The Quick Brown Fox Jumped Over the Lazy Dogs.

Is this doable on a single line?


--
Mark Healey
marknews(at)healeyonline(dot)com

Paul Lalli

unread,
Mar 16, 2005, 11:27:13 AM3/16/05
to
"Mark Healey" <d...@spammer.die> wrote in message
news:pan.2005.03.16....@spammer.die...

> I'm trying to craft a search that capitalizes letters depending on
their
> context, specifically after a space or the beginning of a string.
>
> For example I'd like to turn
>
> the quick brown fox jumped over the lazy dogs.
>
> to
>
> The Quick Brown Fox Jumped Over the Lazy Dogs.
>
> Is this doable on a single line?

What have you tried so far?

Have you read the posting guidelines for this group, posted twice a
week?

Because I'm feeling generous (and bored) anyway:

s/(^|\s)([a-z])/$1\u$2/g;


for more information on ^, |, (), $1 & $2:
perldoc perlre
perldoc perlretut
perldoc perlreref

for more information on \u:
perldoc -f ucfirst

Paul Lalli

Glenn Jackman

unread,
Mar 16, 2005, 11:51:18 AM3/16/05
to
At 2005-03-16 11:14AM, Mark Healey <d...@spammer.die> wrote:
> For example I'd like to turn
> the quick brown fox jumped over the lazy dogs.
> to
> The Quick Brown Fox Jumped Over the Lazy Dogs.
>
> Is this doable on a single line?

my $string = 'the quick brown fox jumped over the lazy dogs.';
my $String = join ' ', map {ucfirst lc} split ' ', $string;

That forces your string to lower case first then capitalizes the first
letter. It won't preserve whitespace though.

--
Glenn Jackman
NCF Sysadmin
gle...@ncf.ca

0 new messages