package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?i).*(?:\d(?:\.\d+)?\s*x\s*)?\K(?<!\d)\d+(?:\.\d+)?(?:k?g|m?l)\b|(?<!\d)\d+(?:\.\d+)?(?:k?g|m?l)(?=\s*x\s*\d)`)
var str = `product brand A 1237ml Bundle of 6
product milk choc370ML
brand milk Vanilla Flavor 850g
One 2400g, For 0-6 Month-Old Infants
a+...two...6-12months...11.2kg...milk
a+...two...11.2kg 6-12months ..milk
Product 200g (10x2g)
[200g] Product
Product A brand(300g)
Product 200g (20g x 10)`
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/