From Stackoverflow
1 2 3 4 5 6 7 |
/^ [a-z0-9]+ # One or more repetition of given characters (?: # A non-capture group. - # A hyphen [a-z0-9]+ # One or more repetition of given characters )* # Zero or more repetition of previous group $/ |
or short
1 |
/^[a-z0-9]+(?:-[a-z0-9]+)*$/ |
Go version
1 |
var slugRegex = regexp.MustCompile(`^[a-z0-9]+(?:-[a-z0-9]+)*$`) |