Using Text::Balanced:
#!/usr/bin/perl -w use strict; use Text::Balanced "extract_delimited"; my @queries = ( qq(QUERY = "SOME QUERY WITH "" (DOUBLE QUOTES)" YEEHA), qq(Johnson looked up and said "Pie is tasty!" People in Clarkstown + liked ""Pie"".), qq("You sir are an ""A\$\@hole""!" The chipmunks were naturally sh +ocked.), qq("""No Way!""" """Way!""") ); for (@queries) { my ($extracted, $remainder, $prefix) = extract_delimited( undef, # defaults to $_ '"', # Our chosen delimiter '[^"]*', # Allow for text before the delimiter '"'); # Escape delimiter when doubled # Strip the delimiter since Text::Balanced leaves it in $extracted =~ s/^\"(.*)\"$/$1/; print; print "\n\$prefix = '$prefix'\n"; print "\$extracted = '$extracted'\n"; print "\$remainder = '$remainder'\n\n"; }
RETURNS:
QUERY = "SOME QUERY WITH "" (DOUBLE QUOTES)" YEEHA $prefix = 'QUERY = ' $extracted = 'SOME QUERY WITH "" (DOUBLE QUOTES)' $remainder = ' YEEHA' Johnson looked up and said "Pie is tasty!" People in Clarkstown liked +""Pie"". $prefix = 'Johnson looked up and said ' $extracted = 'Pie is tasty!' $remainder = ' People in Clarkstown liked ""Pie"".' "You sir are an ""A$@hole""!" The chipmunks were naturally shocked. $prefix = '' $extracted = 'You sir are an ""A$@hole""!' $remainder = ' The chipmunks were naturally shocked.' """No Way!""" """Way!""" $prefix = '' $extracted = '""No Way!""' $remainder = ' """Way!"""'
mixing double delimiters

In reply to Re: How can I find nested delimiters? by ignatz
in thread How can I find nested delimiters? 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.