Here's another approach. Note from the last two lines of the  __DATA__ section that it's easy to put together an example that confuses these regexes: natural language parsing is hard!
use warnings; use strict; MAIN: { my $sq = q{'}; my $dq = q{"}; my $sq_body = qr{ [^\\$sq]* (?: \\. [^\\$sq]* )* }xms; my $dq_body = qr{ [^\\$dq]* (?: \\. [^\\$dq]* )* }xms; my $text = do { local $/; <DATA> }; # slurp all text my @quotes = grep defined && length, # ignore empty captures, null strings $text =~ m{ $dq ($dq_body) $dq | $sq ($sq_body) $sq }xmsg; s{ \n }{ }xmsg for @quotes; # make multi-line quotes into one line print "<$_> \n" for @quotes; } __DATA__ "Mary had a little lamb", she said. She thought, "I'm sure he said 'Wait a tick' before". She wondered, "What happens to an escaped \"?" Also, what happens to a "" or '' null quote? Nobody loves me 'Mary had a large and "wooly" lamb' Do not divide by '0'. Don't divide by '0'. She said, 'I'm sure it'll be ok.'
Output:
<Mary had a little lamb> <I'm sure he said 'Wait a tick' before> <What happens to an escaped \"?> <Mary had a large and "wooly" lamb> <0> <t divide by > <. She said, > <m sure it>

In reply to Re: Trying to find all items in between quotation and speech marks by AnomalousMonk
in thread Trying to find all items in between quotation and speech marks 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.