-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
54 lines (46 loc) · 971 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
package main
import (
"bufio"
"flag"
"fmt"
"github.com/projectdiscovery/gologger"
"os"
"regexp"
)
func main() {
inputRegex := flag.String("r", "", "Your regex [e.g: ^\\w+]")
groupNumber := flag.Int("g", 0, "Group number")
help := flag.Bool("h", false, "Help, show usage parameters")
flag.Parse()
if *inputRegex == "" || *help {
flag.PrintDefaults()
os.Exit(1)
}
_, err := os.Stdin.Stat()
myRegex, err := regexp.Compile(*inputRegex)
checkError(err)
input := readInput()
for _, v := range input {
for _, value := range myRegex.FindAllStringSubmatch(v, -1) {
if len(value) > *groupNumber {
fmt.Println(value[*groupNumber])
}
}
}
}
func readInput() []string {
scanner := bufio.NewScanner(os.Stdin)
var result []string
for scanner.Scan() {
txt := scanner.Text()
result = append(result, txt)
}
return result
}
func checkError(e error) bool {
if e != nil {
gologger.Error().Msg(e.Error())
return true
}
return false
}