use strict;
my $str = '| --------- | -------- | --------- | |propped| - | -a flashlight in one hand and a large leather-bound book (A History of Magic by Bathilda Bagshot) propped open against the pillow. | |Pointless| - | -“Witch Burning in the Fourteenth Century Was Completely Pointless — discuss.”| |unscrewed| - | -Slowly and very carefully he unscrewed the ink bottle, dipped his quill into it, and began to write,| |downtrodden| - | -For years, Aunt Petunia and Uncle Vernon had hoped that if they kept Harry as downtrodden as possible, they would be able to squash the magic out of him.| |sheets,| - | -As long as he didn’t leave spots of ink on the sheets, the Dursleys need never know that he was studying magic by night.| |flinch| - | -But he hoped she’d be back soon — she was the only living creature in this house who didn’t flinch at the sight of him.|';
my $regex = qr/(?<=\|)(?!\s).*?(?!\s)(?=\|)/p;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html