Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: regex: seperating parts of non-formatted names

by fruiture (Curate)
on Sep 09, 2002 at 18:15 UTC ( [id://196376]=note: print w/replies, xml ) Need Help??


in reply to regex: seperating parts of non-formatted names

A good approach to programming problems in general is "breaking the problem into pieces". This is true for regular expressions in general. So I'd start writing the main regexp like that:

$name = qr{($title)?\W+($first)?\W+($middle)?\W+($last)};

And now you define each of the variables on their own, of course above this declaration.

#the title shall be extensible, ok my @titles = qw/LTC COL DR MS MR MISS/; my $title = join('|',@titles); $title = qr[(?:$title)\.]i; #case-insensitive match # first name: no restrictions? my $first = qr[\w+]; # middle initial my $middle = qr{(?:\s*[A-Z]\.)+}; # last name: no restrictions? my $last = qr[\w+];

Any more details should be nop big problem. HTH to <cite>enlighten of the powers of perl</cite> :)

update: untested, there may be more mistakes...

--
http://fruiture.de

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://196376]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-03-28 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found