package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)Name\:\s*(\S*)|host\s*ip\s*\=\s*(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)|host\s*port\s*\=\s*(\d*)`)
var str = `Name: MEmu
NIC 1 Rule(0): name = ADB, protocol = tcp, host ip = 127.0.0.1, host port = 21503, guest ip = 10.0.2.15, guest port = 5555
Name: MEmu_1
NIC 1 Rule(0): name = ADB, protocol = tcp, host ip = 127.0.0.1, host port = 21513, guest ip = 10.0.2.15, guest port = 5555
...`
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/