const regex = /locks:(?<locks>\{.*?\}+[\s*\}]+)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('locks:(?<locks>\\{.*?\\}+[\\s*\\}]+)', 'gm')
const 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`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions