My instincts were that it can be done, since regex's are where perl really shines.

I'm still learning the language, so I've decided to give this a shot just for fun. Jweed's elegant solution (and whoever put it out on cpan) is the best if you're doing this sort of thing for any other purpose than learning the language, though.

Now on to something not quite so elegant:

#!/usr/bin/perl -w use strict; my $string = 'one "two three" four five "six seven eight" nine'; my @list = split / [ ]" #opening quotes | #or "[ ] #closing quotes | [ ] #a space (?!.*?\w") # that's not before any number of characters followed # by a closing quote (allows EOL at quote) /x, $string;

OOC, is it possible to put a character group (and quantify it with a * + ? or {} ) into a look-ahead match?

Crap, this isn't quite there yet. The four and five are sticking together. If anyone has suggestions on how to fix that, I'd appreciate it.


$scratchpad_public = 0 unless $scratchpad;


In reply to Re: In need of a stupid regex trick by David Caughell
in thread In need of a stupid regex trick by 87C751

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.