Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^2: Newbie parsing problem

by mk. (Friar)
on Jan 25, 2007 at 16:42 UTC ( #596541=note: print w/replies, xml ) Need Help??

in reply to Re: Newbie parsing problem
in thread Newbie parsing problem

your solution ignores the name in case there's no middle initial (or just no trailing spaces), which is the first example. adding \W* or \s* instead of a single blank space fixes this.


Replies are listed 'Best First'.
Re^3: Newbie parsing problem
by vaticide (Scribe) on Jan 25, 2007 at 16:47 UTC
    Thanks, I noticed that, too, when I changed it to plug into the test case. Fairly embarrasing considering I do name parsing such as this regularly at work!
      great solutions, I have noticed that:
      my ($last, $first, $middle) = ($name =~ /(\w+)\W*?(\w+)\W*(\w)?/);
      doesn't handle lastnames with hypens in them, any ideas? thanks again!
        \w only matches letters, digits and underscores. since the hyphen is a non-word (\W), that regex interprets it as a separator, so that the second part of the last name is considered the first name.
        the following code supports hyphenated first and last names:
        my ($last, $first, $middle) = ($name =~ /([\w-]+)\W*?([\w-]+)\W*(\w)?/);


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2022-01-21 09:13 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (57 votes). Check out past polls.