Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^4: Stumped by regex

by Fletch (Bishop)
on Dec 06, 2006 at 15:32 UTC ( [id://588111]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Stumped by regex
in thread Stumped by regex

You might even prefer [[:alpha:]]+ instead of hard coding a-z in case you ever need to work in non-ASCII-betic locales.</pedant>

Replies are listed 'Best First'.
Re^5: Stumped by regex
by OfficeLinebacker (Chaplain) on Dec 06, 2006 at 16:19 UTC
    You beat me to it. I saw [a-zA-Z] and thought [[:alpha:]] might be shorter (it's not, due to the colons and extra set of brackets). Then I saw [a-z] with /i which blew it away. But [[:alpha:]] is more portable.

    Also, isn't OP talking about surnames only? I believe surname means last name. So spaces are rare special instances that must be dealt with, not a requirement. (In my area, it's far more common to see single word last names, then in multi-word last names, hyphens are more common delimiters than spaces, so you might want to include hyphens in your regex as well)

    So if the regex sees "Larry Wall," it thinks that is someone's LAST name only, as "Larry Wall, Joe" if you're doing Last, First. If it sees "GeorgeWashington," that's just a last name, etc.

    The main thing I would add is that unless you're sure there will be no hyphenated names (perhaps you're instructing users to enter spaces in place of hyphens?), I'd include a hyphen in addition to a space.

    If you want to be really robust, you could check for capitalization only at the right places (after space, Hyphen, or a lower-case 'c' at either the second letter in a word that starts with 'M' or the third letter in a word that starts with 'Ma.' Also, in your spec you specify a maximum of one space; I don't know if there are double-hyphenated surnames out there.

    _________________________________________________________________________________

    I like computer programming because it's like Legos for the mind.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-19 18:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found