Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: simpler regex

by rsiedl (Friar)
on May 16, 2007 at 03:36 UTC ( [id://615679]=note: print w/replies, xml ) Need Help??


in reply to Re: simpler regex
in thread simpler regex

That would be ideal, but i cant be guaranteed the user will input the data correctly. i.e. they may put in the middle name section "P J"...

Replies are listed 'Best First'.
Re^3: simpler regex
by graff (Chancellor) on May 16, 2007 at 05:16 UTC
    That's easy enough to accommodate:
    sub fullname { my @parts = @_; for ( @parts ) { s/(?<!\S)([A-Z])(?!\S)/$1./g; } return join " ", @parts; }
    Of course, given that sort of regex, I guess it doesn't matter whether you join the parts before or after the substitution. (It's using negative look-behind and negative look-ahead to check that a single upper-case letter is neither preceded nor following by a non-whitespace character, and in that case, put a period after the letter.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2026-02-07 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.