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.)