$re = '/(?:\bmembers\s*\{|(?<!^)\G[^{]+\{[^}]+\})\s*?\n\s*([^:{}]+)(?=:\d)/s';
$str = 'ltm pool TEST_POOL {
Some strings
above headers
records {
baz:1 {
ANY STRING
HERE
}
foobar:23 {
ALSO ANY
STRING HERE
}
}
members {
qux:45 {
ALSO ANY
STRINGS HERE
}
bash:2 {
AND ANY
STRING HERE
}
topaz:789 {
AND ANY
STRING HERE
}
}
Some strings
below headers
}';
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