$re = '/(datatype\s+: 4\b(?:(?!datatype\s+: \d)[\s\S])*?(maxlength\s+:\s0\b))/';
$str = 'field {
id : 536870914
name : Set Field (Submit Mode)
datatype : 4
fieldtype : 1
create-mode : 2
option : 2
timestamp : 1489159658
owner : John Smith
last-changed : John Smith
length-units : 0
maxlength : 0
clob-store-opt : 0
menu-style : 1
qbe-match-op : 1
fulltext-optns : 0
permission : 12\\1
}
field {
id : 536870915
name : Schema Name
datatype : 4
fieldtype : 1
create-mode : 2
option : 1
timestamp : 1165057260
owner : John Smith
last-changed : John Smith
length-units : 0
maxlength : 30
clob-store-opt : 0
menu-style : 1
qbe-match-op : 1
fulltext-optns : 0
permission : 12\\1
}
field {
id : 536870916
name : Type
datatype : 4
fieldtype : 1
create-mode : 2
option : 1
timestamp : 1165057260
owner : John Smith
last-changed : John Smith
length-units : 0
maxlength : 30
clob-store-opt : 0
menu-style : 2
qbe-match-op : 1
fulltext-optns : 0
permission : 12\\1
}
field {
id : 536870917
name : Set Field (Query Mode)
datatype : 4
fieldtype : 1
create-mode : 2
option : 2
timestamp : 1489159658
owner : John Smith
last-changed : John Smith
length-units : 0
maxlength : 0
clob-store-opt : 0
menu-style : 1
qbe-match-op : 1
fulltext-optns : 0
permission : 12\\1
}';
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