package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)timeout\shttp-request\s+\d+(?=[\s\S]+defaults)`)
var str = `global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 32768
tune.maxaccept -1
chroot /var/lib/haproxy
daemon
timeout http-request 5000
stats socket /var/run/haproxy.sock mode 600 level admin
stats timeout 2m
defaults
log global
mode http
option httplog
option dontlognull
retries 5
option redispatch
maxconn 16384
timeout connect 7s
timeout client 500s
timeout server 500s
timeout http-request 7000
timeout client-fin 30s
timeout tunnel 1h`
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/