$re = '/^begin.*(?:\n(?!begin|end$).*)*\b536916223\b.*(?:\n(?!begin|end$).*)*\nend$/m';
$str = 'begin active link
export-version : 11
actlink-order : 2
wk-conn-type : 1
schema-name : HelpDesk
actlink-mask : 1
actlink-control: 750000002
enable : 1
action {
set-field : 0\\536916222\\101\\4\\1\\1\\
}
errhandler-name:
end
begin active link
export-version : 11
actlink-order : 2
wk-conn-type : 1
schema-name : HelpDesk
actlink-mask : 1
actlink-control: 610000092
enable : 1
permission : 0
action {
id : 536916223
focus : 0
access-opt : 1
option : 0
}
action {
set-field : 0\\536916222\\101\\4\\1\\1\\
}
errhandler-opt : 0
errhandler-name:
end
begin active link
actlink-order : 12
wk-conn-type : 1
schema-name : HelpDesk
actlink-mask : 2064
enable : 1
permission : 0
action {
id : 536916223
focus : 0
access-opt : 1
option : 0
}
action {
set-field : 0\\536916222\\101\\4\\1\\1\\
}
errhandler-opt : 0
errhandler-name:
end';
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