package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?im)(\+|\-)?(\d{1,})(?:\s|)(ms|millisecond(?:\(s\)|s|)|second(?:\(s\)|s|)|sec|s(?:\s|$)|minute(?:\(s\)|s|)|min|m(?:\s|$)|h(?:\s|$)|hour(?:\(s\)|s|)|h(?:\s|$)|day(?:\(s\)|s|)|d(?:\s|$)|week(?:\(s\)|s|)|w(?:\s|$)|month(?:\(s\)|s|)|mm(?:\s|$)|year(?:\(s\)|s|)|y(?:\s|$))(?:\s|$)?`)
var str = `+1ms
+19milliseconds
+7 milliseconds
-1 millisecond
+7 s
+8 s
+4 seconds
-1 second
+10 minutes
+1A minutes
-1 minute
+1m
-1m
+1 m
-2 m
1 more time
1min
1 min
+19 hours
-1 hour
+1h
-1h
+1 h
-2 h
+1 day(s)
+2 week(s)
+3mm
+3 month(s)
+4 year(s)
1ms
public Myles +1 minute
Porter Robinson & Madeon - Shelter - Acapella Cover
haha xd +4 years lol`
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/