package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)locks:(?<locks>\{.*?\}+[\s*\}]+)`)
var 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`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
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 Golang, please visit: https://golang.org/pkg/regexp/