in reply to Split first and last names
G'day Bod,
I agree with others that you should change the form. Ask specifically for first name and last name.
"The obvious problem is that it fails with extended characters such as Zoë."
Take a look at perlrecharclass and follow links from there.
This code is not intended as a solution to your problem; it's just to demonstrate some options that are available:
$ perl -Mstrict -Mwarnings -Mutf8 -C -E '
my $n = "Zoë Åcçéñt-Smythe";
my ($f, undef, $l)
= $n =~ /([[:alpha:]]+)( +|\Z)([\p{Alpha}\p{Punct}]*)/;
say $f;
say $l;
'
Zoë
Åcçéñt-Smythe
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Split first and last names
by Bod (Parson) on Nov 12, 2022 at 23:29 UTC | |
by kcott (Archbishop) on Nov 13, 2022 at 01:23 UTC |