Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.


In reply to Re^5: Stumped by regex by OfficeLinebacker
in thread Stumped by regex by brickwall

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found