package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?mi)P(ost)?[\.\s]*(O|0)(ff(ice)?)?[\.\s]+B(o|0)x`)
var str = `PO Box
P.O. Box
PO. Box
po box
P.o box
PoBox
p.o. Box
post office box 716
Post O. box
Post off box
p office box
p off BOX
p0 box
p0ffice box k`
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/