use strict;
my $str = '
// It\'s better to create the object with the right prototype from the start.
type TJS_SetPrototype = function (cx: PJSContext; var obj: PJSObject;
var proto: PJSObject):Boolean; cdecl;
var JS_SetPrototype: TJS_SetPrototype external SpiderMonkeyLib name \'SM_SetPrototype\';
/// Write access an object\'s reserved slots
type TJS_SetReservedSlot = procedure (obj: PJSObject; index: uint32;
var v: jsval); cdecl;
var JS_SetReservedSlot: TJS_SetReservedSlot external SpiderMonkeyLib name \'SM_SetReservedSlot\';
';
my $regex = qr/type\s([_A-Za-z]+)\s*=\s*(function|procedure)(.*?cdecl;)\s*var(\s[_A-Za-z]+):\s*([_A-Za-z]+)\s(external.*?;)/sp;
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