How to ask questions the smart way.

I assume you mean you're using split(m/[A-Z]/, $string), but you didn't make that very clear.

The split() pattern defines what to remove between the chunks you want to keep. Using a m// pattern with captures defines what to keep amongst the rest of the string.

This method catches a list of capitalized chunks, and is the more natural to me:

my $name = 'JohnJacobJingleheimer-Schmidt'; my @chunks = ($name =~ m/([A-Z][a-z]*)/g); print $_,$/ for @chunks;

By using a couple of zero-width assertions, you could use split(), but it will act differently with punctuation cases:

my $name = 'JohnJacobJingleheimer-Schmidt'; my @chunks = split(m/(?<=[a-z])(?=[A-Z])/, $name); print $_,$/ for @chunks;

--
[ e d @ h a l l e y . c c ]


In reply to Re: split by a capital followed by by halley
in thread split by a capital followed by by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.