the problem: to extract strings from single quoted-like expressions...
my code (and some sample data):
#!/usr/bin/perl -Twl use strict; { local undef $/; my $string = <DATA>; # extract strings from 'usual' quotes: print 'MATCH: ', $2 while $string =~ /\bq([^\w{([])(.+?[^\\])\1/sg +; # extract strings from 'bracketted' quotes: for (( [ qw'{ }' ], [ qw'[ ]'], [ qw'( )' ] )) { print 'MATCH: ', $1 while $string =~ /\bq\Q$_->[0]\E(.+?[^\\])\Q$_->[1]\E/sg; } } __DATA__ my $km = q'BEGIN simple foo bar baz END'; my $kv = q#BEGIN foo bar \# baz END#; my $kk = q{BEGIN super foo bar banzai END}; my $kt = q{BEGIN super foo \{super\} bar banzai END};

the wisdom i'm looking for now is if i could unify that 2 scenarios above in a single one with a smarter regexp or smth... ofc, there still should be some kind of efficiency in the resulting regexp ... if possible ;-)

... i really wonder how my code would have looked like if i was supposed to match interpolated stuff like qq{ foo $bar{baz} :) } .. but that's another story to think of :)

--
AltBlue.

In reply to matching single-quoted-like strings (q{}, q//) by AltBlue

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.