use strict;
my $str = 'The National Weather Service in Milwaukee/Sullivan has issued a
* Tornado Warning for...
Northwestern Columbia County in south central Wisconsin...
Southwestern Marquette County in south central Wisconsin...
* Until 945 PM CDT.
* At 911 PM CDT, a severe thunderstorm capable of producing a tornado
was located 8 miles east of Wisconsin Dells, moving northeast at 45
mph.
HAZARD...Tornado.
SOURCE...Radar indicated rotation.
IMPACT...Flying debris will be dangerous to those caught without
shelter. Mobile homes will be damaged or destroyed.
Damage to roofs, windows, and vehicles will occur. Tree
damage is likely.
* Locations impacted include...
Packwaukee, Endeavor and Briggsville.';
my $regex = qr/Tornado Warning for\.\.\.(?:\n.*)*?\n\n/mp;
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