package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`editor\s*\{[^{}"]*
# Notice that I enabled the /x flag ----->
# That just allows me to add comments here to make it more readable
# Match from opening to closing double quote for the 'key'
"[^"]*"
# Then any whitespace between the 'key' and 'value'
\s+
# Match from opening to closing double quote for the 'value'
"[^"]*"`)
var str = `"entity"
{
"id" "5040044"
"classname" "weapon_defibrillator_spawn"
"angles" "0 0 0"
"body" "0"
"disableshadows" "0"
"skin" "0"
"solid" "6"
"spawnflags" "3"
"origin" "449.47 5797.25 2856"
editor
{
"color" "0 0 200"
"visgroupshown" "1"
"visgroupautoshown" "1"
"logicalpos" "[-13268 14500]"
}
editor
{
"color" "0 0 200"
"visgroupshown" "1"
"visgroupautoshown" "1"
"logicalpos" "[-13268 14500]"
"specialchars" "}"
}
editor
{
"child" "0 0 200"
"visgroupshown" "1"
"visgroupautoshown" "1"
"logicalpos" "[-13268 14500]"
subgroup
{
"child" "42 42 42"
}
}
}
`
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/