in reply to regexp on utf8 string

The good thing about functions such as ucfirst is that they're locale-friendly. You don't really have to worry about what upper-case characters map to what lower-case characters in a given character set; ucfirst knows. Try this:

my $string = "word1 word2 word3"; $string = join ' ', map { ucfirst } split /\s+/, $string;

It ought to do the trick. ...just one way to do it.

A slightly more robust regexp solution might include the following:

use strict; use warnings; my $string = "word1 word2 word3"; $string =~ s/(\w+)(?=\W|$)/ucfirst $1/eg;

Dave

Replies are listed 'Best First'.
Re^2: regexp on utf8 string
by fredvdv (Novice) on Sep 12, 2004 at 16:31 UTC
    I finally manage to do the tricks with these:

    uppercase the first letter and lowercase the rest
    $string = "\u\L$string";
    my string always contains spaces and/or dashes so I uppercase each letters which follows one or more spaces or dashes.
    $string =~ s/([\s-]+)(.)/$1\u$2/g;
    Regards, Frederic