4
4
4upik2018-04-10 19:42:01
Perl
4upik, 2018-04-10 19:42:01

How to make the first capital and the rest lowercase except for latin with Perl regular expressions?

How to make the first capital and the rest lowercase except for latin with Perl regular expressions?
There is text
Name HP MODEL Description
Name Description
Name HP
How to get
Name Hp Model Description
Name Description
Name Hp

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya33, 2018-04-11
@Ilya33

The first thing that came to mind:

use utf8;

my @a = (
    "Название HP MODEL описание",
    "название описание",
    "Название HP"
);

for my $str (@a) {
    $str = ucfirst(lc($str));
    $str =~ s/\b([a-zA-Z])/uc($1)/eg;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question