$re = '/locks:(?<locks>\{.*?\}+[\s*\}]+)/m';
$str = '[conn5695298] query entitydb_20014.chats query: { $query: { $or: [ { receiver_id: "5b91eb3dfe860a5325533467" }, { sender_id: "5b91eb3dfe860a5325533467" } ], send_time: { $gt: 0 } }, $orderby: { send_time: -1 } } planSummary: COLLSCAN, COLLSCAN ntoreturn:120 ntoskip:0 nscanned:0 nscannedObjects:2216688 scanAndOrder:1 keyUpdates:0 writeConflicts:0 numYields:18133 nreturned:0 reslen:20 locks:{ Global: { acquireCount: { r: 36268 }, acquireWaitCount: { r: 49 }, timeAcquiringMicros: { r: 8560 } }, MMAPV1Journal: { acquireCount: { r: 18134 }, acquireWaitCount: { r: 2 }, timeAcquiringMicros: { r: 554 } }, Database: { acquireCount: { r: 18134 } }, Collection: { acquireCount: { R: 18134 } } } 4547ms
planSummary: IXSCAN { host: 1, gid: 1, service_code: 1, name: 1, instance: 1 } cursorid:44314245057 keysExamined:20225 docsExamined:20050 cursorExhausted:1 numYields:158 nreturned:20050 reslen:1596954 locks:{ Global: { acquireCount: { r: 318 } }, Database: { acquireCount: { r: 159 } }, Collection: { acquireCount: { r: 159 } } } protocol:op_command 136ms
planSummary: IXSCAN { host: 1, gid: 1, service_code: 1, name: 1, instance: 1 } cursorid:44314245057 keysExamined:20225 docsExamined:20050 cursorExhausted:1 numYields:158 nreturned:20050 reslen:1596954 locks:{ Global: 5 }, Database: { acquireCount: { r: 159 } }} }} }}}} }}}}}}, Collection: { acquireCount: { r: 159 } } } protocol:op_command 136ms';
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