Created
September 2, 2022 10:31
-
-
Save firminochangani/9a76d3640950bd52cf41ef3d31a8c6d0 to your computer and use it in GitHub Desktop.
Regex to match a slug in Go (Lang)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"regexp" | |
) | |
// Regex source: https://ihateregex.io/expr/url-slug/ | |
func main() { | |
str := "Hello my new % calendar id 09" | |
str2 := "hello-this-is-my-slug" | |
isMatched, err := regexp.Match("^[a-z/d]+(?:-[a-z/d]+)*$", []byte(str2)) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(str) | |
fmt.Println(str2) | |
fmt.Println("Is matched: ", isMatched) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment