use strict;
my $str = 'This module provides regular expression matching operations.
Regular expressions use the backslash character (\'\\\') to indicate special forms
or to allow special characters to be used without invoking their special
meaning.
Python Regular Expression 02 December 1999
Python Proprietary
----------------------- Page 292-----------------------
PYTHON RE SPECIFICATION Version 2.7 [Vol 9, Part Q] page 983
Python Regular Expression Specification
It is important to note that most regular expression operations are available as
module-level functions and RegexObject methods. The functions are shortcuts that
don’t require you to compile a regex object first, but miss some fine-tuning
parameters.';
my $regex = qr/^.*?Python Regular Expression.*?$(*SKIP)(*FAIL)|^.*?Python Proprietary.*?$(*SKIP)(*FAIL)|.*?Page \d+.*?$(*SKIP)(*FAIL)|^$(*SKIP)(*FAIL)|^.*?$/mip;
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