package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?mi)(err\s*?\d{1})|[^\d]\s+(\d{3})(?:$|\s+(?!\d))`)
var str = `The below items should match:
-----------------------------
123
456 123
123 324 324
Match the number in this sentence 123 as well
999
The below items should NOT match:
---------------------------------
1234
12345
123456
1234567
£123
$456
Err404
ERR404
err404
Err 404
ERR 404
err 404
there is err 404 on page
this err 1232222222222 as well
a string 12323 like this
asd
4444333322221111
4444 3333 2222 1111
Err123
02012341234
920 1234 1234`
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/