package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)(?<=sda1)\s+(?|(\d+.?\d+)[G,M.L,%]?)\s+(?|(\d+.?\d+)[G,M.L,%]?)\s+(?|(\d+.?\d+)[G,M.L,%]?)\s+(\d+)%`)
var str = `Filesystem Size Used Avail Use% Mounted on
udev 3.8G 0 3.8G 0% /dev
tmpfs 806M 5.3M 800M 1% /run
/dev/mmcblk0p2 235G 59G 164G 27% /
tmpfs 4.0G 0 4.0G 0% /dev/shm
tmpfs 5.0M 48K 5.0M 1% /run/lock
/dev/mmcblk0p1 510M 63M 448M 13% /boot/firmware
/dev/sda1 137.8G 299.88G 127G 3% /media/usbplatte
tmpfs 806M 0 806M 0% /run/user/1000
/dev/sda1 139752 2662 129920 3% /media/usbplatte
`
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/