$re = '/timeout\shttp-request\s+\d+(?=[\s\S]+defaults)/m';
$str = 'global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 32768
tune.maxaccept -1
chroot /var/lib/haproxy
daemon
timeout http-request 5000
stats socket /var/run/haproxy.sock mode 600 level admin
stats timeout 2m
defaults
log global
mode http
option httplog
option dontlognull
retries 5
option redispatch
maxconn 16384
timeout connect 7s
timeout client 500s
timeout server 500s
timeout http-request 7000
timeout client-fin 30s
timeout tunnel 1h';
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