Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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 avoiding work at the Monastery: (14)
As of 2015-07-03 07:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (48 votes), past polls