in reply to Split: Having your capitals and not eating them

Capturing what you split upon will return the split boundaries:

perl -le 'print $_ for split( /([A-Z])/, shift)' AbcDefGhi A bc D ef G hi

Note that edan's solution does something slightly different:

% perl -le 'print $_ for split( /(?=[A-Z])/, shift )' AbcDefGhi Abc Def Ghi

Choose your poison :)

- another intruder with the mooring of the heat of the Perl

Replies are listed 'Best First'.
Re^2: Split: Having your capitals and not eating them
by tachyon (Chancellor) on Nov 11, 2004 at 13:47 UTC

    It is probably the former, given the post.....

    print join ' | ', split /(?=[A-Z])/, "thisIsCamelCase"; __DATA__ this | Is | Camel | Case

      I think you mean "the latter." ;-)

      --
      edan

        I meant the former as in your original post rather than the alternative interpretation. I knew what I was talking about, even if it was not obvious to anyone else :-)

        After reading edan's first reply I discovered that what I really wanted to do was:

        $s =~ s/(?=[A-Z])/ /g;

        i.e. more the 'latter', although I look forward to doing the former at some point.

        Thanks, everyone,

        loris