$re = '/((|\s|\n)*subnet(|\s|\n)*((\d{1,3}.){3}(\d{1,3}))(|\s|\n)*netmask(|\s|\n)*((\d{1,3}.){3}(\d{1,3}))(|\s|\n)*\{(|\s|\n)+((|\s|\n)+host(|\s|\n)*(\w+)(|\s|\n)*\{(|\s|\n)*(\w*)\:(\w*)\;(|\s|\n)*\}(|\s|\n)*)*\})/';
$str = '#DHCP Server Configuration file.
deny unknown-clients;
subnet 10.8.140.2 netmask 255.255.255.255 {
host example{
optian:param;
}
host example2{
option2:param2;
}
}
subnet 20.8.110.1 netmask 255.255.255.255 {
host example{
optian:param;
}
}
subnet 20.8.110.1 netmask 255.255.255.255 {
}';
preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 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