Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Splitting on non-initial uppercase without split

by edan (Curate)
on Jan 26, 2005 at 10:46 UTC ( #425168=note: print w/ replies, xml ) Need Help??


in reply to Splitting on non-initial uppercase without split

This works, but I have the distinct feeling there is a more straightforward way to do it...

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


Comment on Re: Splitting on non-initial uppercase without split
Download Code
Re^2: Splitting on non-initial uppercase without split
by tphyahoo (Vicar) on Jan 26, 2005 at 12:03 UTC
    How about:
    $s =~ s/([a-z])([A-Z])/$1 $2/ig;
    (untested)
      I guess you would want to make your regex case sensitive:
      $s =~ s/([a-z])([A-Z])/$1 $2/g;

      But then I think it still would not fit the description as it
      woud not split something like "Test1Test2" into "Test1 Test2"
      So following your line of thought it should be something like
      $s =~ s/([^A-Z])([A-Z])/$1 $2/g;

      si_lence
Re^2: Splitting on non-initial uppercamse without split
by ambrus (Abbot) on Jan 26, 2005 at 20:09 UTC

    What about this:

    $s =~ s/\B(?=[[:upper:]])/ /g;
    or this
    $s =~ s/\B([[:upper:]])/ $1/g;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-08-02 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (55 votes), past polls