Created
October 26, 2018 18:41
-
-
Save ivanitskiy/d43890e981b79765c92447c44c702df1 to your computer and use it in GitHub Desktop.
Match strings by wildcard patterns with filepath.Match() function
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" | |
| "path/filepath" | |
| ) | |
| func main() { | |
| filename := "start.txt" | |
| pattern := "*art*" | |
| matched, err := filepath.Match(pattern, filename) | |
| if err != nil { | |
| fmt.Println(err) | |
| } | |
| fmt.Println(matched) | |
| //--------------------------------- | |
| pattern = "*fart*" | |
| matched, err = filepath.Match(pattern, filename) | |
| if err != nil { | |
| fmt.Println(err) | |
| } | |
| fmt.Println(matched) | |
| //--------------------------------- | |
| filename = "data123.csv" | |
| pattern = "data[0-9]*" | |
| matched, err = filepath.Match(pattern, filename) | |
| if err != nil { | |
| fmt.Println(err) | |
| } | |
| fmt.Println(matched) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment