package mysql

import (
	"regexp"
)

func ParseSqlConnDBName(conn string) string {
	pattern := regexp.MustCompile(
		`^(?:(?P<user>.*?)(?::(?P<passwd>.*))?@)?` + // [user[:password]@]
			`(?:(?P<net>[^\(]*)(?:\((?P<addr>[^\)]*)\))?)?` + // [net[(addr)]]
			`\/(?P<dbname>.*?)` + // /dbname
			`(?:\?(?P<params>[^\?]*))?$`) // [?param1=value1&paramN=valueN]
	matches := pattern.FindStringSubmatch(conn)
	// tlsConfigRegister := make(map[string]*tls.Config)
	names := pattern.SubexpNames()

	for i, match := range matches {
		switch names[i] {
		case "dbname":
			return match
		}
	}

	return ""
}
