package pkg import "regexp" var LVSCANRE = regexp.MustCompile(`(?i)([a-z]+)\s+'(.*?)'\s+\[(.*?)\]\s+(\S+)`) type ( LvScan struct { Volumes []*Volume `json:"volumes"` } Volume struct { State string `json:"state"` Name string `json:"name"` Size string `json:"size"` Status string `json:"status"` } ) func (l *LvScan) Parse(s string) { for _, v := range LVSCANRE.FindAllStringSubmatch(s, -1) { l.Volumes = append(l.Volumes, &Volume{ State: v[1], Name: v[2], Size: v[3], Status: v[4], }) } }