-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
56 lines (43 loc) · 863 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"bufio"
"fmt"
"os"
"regexp"
"strconv"
"strings"
)
func regx(input string) string {
ilevel, _ := strconv.Atoi(input)
prefix := "("
center := "\\w*\\."
suffix := "\\w*$)"
fmiddle := strings.Repeat(center, ilevel)
pattern := prefix + fmiddle + suffix
return pattern
}
func scanner() {
lines := make(map[string]bool)
re := regexp.MustCompile(regx(os.Args[1]))
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
result := re.FindAllString(scanner.Text(), -1)
for _, domain := range result {
//Remove duplicates from result
if lines[domain] {
continue
}
lines[domain] = true
fmt.Println(domain)
}
}
}
func main() {
info, _ := os.Stdin.Stat()
if len(os.Args) > 1 && info.Mode()&os.ModeNamedPipe != 0 {
input, _ := strconv.Atoi(os.Args[1])
if input > 0 {
scanner()
}
}
}