From 5c6b606da8d1c9853e88e2f7f8294f6ba160b418 Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Mon, 6 May 2019 01:30:56 +0300 Subject: [PATCH] add: regex to map as sets example --- 23-input-scanning/02-map-as-sets/main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/23-input-scanning/02-map-as-sets/main.go b/23-input-scanning/02-map-as-sets/main.go index b66b0ed..71426e4 100644 --- a/23-input-scanning/02-map-as-sets/main.go +++ b/23-input-scanning/02-map-as-sets/main.go @@ -11,6 +11,8 @@ import ( "bufio" "fmt" "os" + "regexp" + "strings" ) func main() { @@ -24,11 +26,21 @@ func main() { in := bufio.NewScanner(os.Stdin) in.Split(bufio.ScanWords) + rx := regexp.MustCompile(`[^a-z]+`) + words := make(map[string]bool) for in.Scan() { - words[in.Text()] = true + word := strings.ToLower(in.Text()) + word = rx.ReplaceAllString(word, "") + if len(word) > 2 { + words[word] = true + } } + // for word := range words { + // fmt.Println(word) + // } + if words[query] { fmt.Printf("The input contains %q.\n", query) return