$re = '/type\s([_A-Za-z]+)\s*=\s*(function|procedure)(.*?cdecl;)\s*var(\s[_A-Za-z]+):\s*([_A-Za-z]+)\s(external.*?;)/s';
$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\';
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
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 PHP, please visit: http://php.net/manual/en/ref.pcre.php