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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.