package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(\[\d{3,5} ?x ?\d{3,5}\])`)
var str = `Should match:
Hey guys check out this awesome hi-def picture! [320x480]
[F]irst time here plz be nice [6969x6969]
Spaces around the x [123 x 456]
herp derp durr (smallest dimensions that will match) [100x100]
Check out this massive 2.1 jiggapixel image of the entire USA in high detail! (highest dimensions that will match) [99999x99999]
Should not match:
Please go to this spammy site and buy shit so we can steal your credit card (no tag)
Letters in the tag [i234x5678]
Dimension too small [99 x 123]
Dimension too big [100000 x 123]
Wrong bracket {123 x 456]
`
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/