package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`((|\s|\n)*subnet(|\s|\n)*((\d{1,3}.){3}(\d{1,3}))(|\s|\n)*netmask(|\s|\n)*((\d{1,3}.){3}(\d{1,3}))(|\s|\n)*\{(|\s|\n)+((|\s|\n)+host(|\s|\n)*(\w+)(|\s|\n)*\{(|\s|\n)*(\w*)\:(\w*)\;(|\s|\n)*\}(|\s|\n)*)*\})`)
var str = `#DHCP Server Configuration file.
deny unknown-clients;
subnet 10.8.140.2 netmask 255.255.255.255 {
host example{
optian:param;
}
host example2{
option2:param2;
}
}
subnet 20.8.110.1 netmask 255.255.255.255 {
host example{
optian:param;
}
}
subnet 20.8.110.1 netmask 255.255.255.255 {
}`
if len(re.FindStringIndex(str)) > 0 {
fmt.Println(re.FindString(str),"found at index",re.FindStringIndex(str)[0])
}
}
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/