package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?iU)(?<!^)(\d{1,2}\s?x\s?)?\d{1,2}((,|\.)\d{1,2})?\s?L?`)
var str = `25 Test Drink 60% 12x1,0L
Test Drink 60% 2x0,5
Test Drink 3 x 0,75 L
Test Drink 4x0,75 L
Test Drink 5 x 0,75L
Test Drink 66 x 0,75
Test Drink 0,75
Test Drink 0.75
7UP 12 x 1 L`
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/