package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?mi)\b[A-Z]{2}\d\d(?:(?: ?[A-Z\d]{4}){2,6} ?[A-Z\d]{3}|( ?[A-Z\d]{4}){3,7}(?: ?[A-Z\d]{1,2})?)\b`)
var str = `NL64ABNC0417164300
NL64 ABNC 0417 164
NL64 ABNC 0417 1643
NL64 ABNC 0417 1643 0
NL64 ABNC 0417 1643 012
NL64 ABNC 0417 1643 0123
NL64 ABNC 0417 1643 0123 0
NL64 ABNC 0417 1643 0123 0123 0123 0123 01
This is a customer iban DE89 3704 0044 0532 0130 00 from somewhere
`
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/