Welcome to the Monastery | |
PerlMonks |
Re: Split first and last namesby kcott (Archbishop) |
on Nov 10, 2022 at 00:42 UTC ( [id://11148084]=note: print w/replies, xml ) | Need Help?? |
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
In Section
Seekers of Perl Wisdom
|
|