package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?<!\d)20\d{6}\D?\d{6}(?!\d)`)
var str = `a20171217091011 = None instead of 2017-12-17 09:10:11
b20171217091011 = None instead of 2017-12-17 09:10:11
20171217091011 = None instead of 2017-12-17 09:10:11
-20171217091011 = None instead of 2017-12-17 09:10:11
_20171217091011 = None instead of 2017-12-17 09:10:11
aa20171217091011 = None instead of 2017-12-17 09:10:11
a1-20171217091011 = None instead of 2017-12-17 09:10:11
123_20171217091011 = None instead of 2017-12-17 09:10:11
123 20171217091011 = None instead of 2017-12-17 09:10:11
123=20171217091011 = None instead of 2017-12-17 09:10:11
201712170910110 = 2017-12-17 09:10:11 instead of None
a20171217091011a = None instead of 2017-12-17 09:10:11
(20171217091011) = None instead of 2017-12-17 09:10:11
a-20171217091011 b = None instead of 2017-12-17 09:10:11
123(20171217091011)456 = None instead of 2017-12-17 09:10:11
20171217091011 = None instead of 2017-12-17 09:10:11
2017 20171217091011 2017 = None instead of 2017-12-17 09:10:11
20171218-20171217091011-070809 = 2017-12-18 20:17:12 instead of 2017-12-17 09:10:11
123(20171217-091011)456 = None instead of 2017-12-17 09:10:11
a2017(20171217 091011)b = None instead of 2017-12-17 09:10:11
2017xx(20171217?091011)cc2017 = None instead of 2017-12-17 09:10:11
A-20171116-080910-20171217091011 = None instead of 2017-11-16 08:09:10`
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/