Bis <[EMAIL PROTECTED]> wrote:
I want to make the case of the first letter of all the words in a
selected string to upper case. The code

s/\b(\w+)/\u$1\E/g;

enables me to do this for the whole document.

But the string I want to match and operate on is all instances of text
following the string

SCTN:

as in

SCTN: News Analysis

or

SCTN: Special Report

But when I try

s/(SCTN:\s*)\b(\w+)/$1\u$2\E/g;

nothing seems to change? : (

That will only change the first letter of the first word after 'SCTN:'. That's what you're seeing, right? If you want to change *all* the words after SCTN: to start with uppercase (and leave the ones before it alone), maybe something like this:


my $text = q(leave this alone SCTN: this isn't capitalized but should be);
if (/SCTN:/) {
   my ($before, $after) = split /SCTN:/, $text, 2;
   $after =~ s/(\S+)/\u$1/g;
   $text = $before . 'SCTN:' . $after;
}
print $text;

I used \S instead of \w in an attempt to handle contractions such as "can't" and "don't", etc.

Now I'd almost bet someone (John Krahn?) will come up with a more clever approach and make it into a one-liner. :-)



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to