#!/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};
... 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 :)
In reply to matching single-quoted-like strings (q{}, q//) by AltBlue
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |