Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Insert Space between names

by pg (Canon)
on Nov 21, 2005 at 01:43 UTC ( #510334=note: print w/replies, xml ) Need Help??

in reply to Insert Space between names

One solution:

my $string = "JohnDoe"; $string =~ s/(.)([A-Z])/$1 $2/g; print $string;

Replies are listed 'Best First'.
Re^2: Insert Space between names
by GrandFather (Sage) on Nov 21, 2005 at 01:47 UTC

    Note that that puts a space in front of John.

    DWIM is Perl's answer to Gödel
      Depends on whether the string consists only of the name (or more precisely, starts with the name) or not. If it does then there's no extra space.

        Following the stealth update that is true. When I commented, the code was:

        my $string = "JohnDoe"; $string =~ s/([A-Z])/ $1/g; print $string;

        DWIM is Perl's answer to Gödel
Re^2: Insert Space between names
by Aristotle (Chancellor) on Nov 21, 2005 at 09:30 UTC

    You could fix your original code less invasively with

    s/(?<!^)([A-Z])/ $1/g;

    But [A-Z] only works for English, at most, and should be avoided.

    s/(?<!^)(\p{Upper})/ $1/g;

    Makeshifts last the longest.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://510334]
[Corion]: erix: I'm not sure if it really is MySQL - maybe MS SQL also has LIMIT 0
[erix]: it has TOP, IIRC
[Corion]: erix: Ah. I use where 1 = 0 for queries where I only am interested in the structure ;)
[erix]: 1=0 is as short as TOP :)

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2017-01-23 09:29 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (192 votes). Check out past polls.