Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Splitting on non-initial uppercase without split

by edan (Curate)
on Jan 26, 2005 at 10:46 UTC ( [id://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

Replies are listed 'Best First'.
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;
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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-19 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found