This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
str.go
67 lines (61 loc) · 1.47 KB
/
str.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
57
58
59
60
61
62
63
64
65
66
67
// For all functions that manipulate strings
package main
import (
"fmt"
"regexp"
"strings"
)
func stringInSlice(s string, a []string) bool {
for _, thing := range a {
if thing == s {
return true
}
}
return false
}
func textFilter(input string) string {
reg, err := regexp.Compile("[^a-zA-Z0-9_]+")
if err != nil {
fmt.Println("Error compiling regexp:", err)
return "" // return empty string because more errors would occur otherwise
}
outputString := reg.ReplaceAllString(input, "")
return outputString
}
// ContainsAnySubstring Checks if any of the substrings in the array are in the test string
func ContainsAnySubstring(testString string, strArray []string) bool {
for _, str := range strArray {
if strings.Contains(testString, str) {
return true
}
}
return false
}
func textFilterSlice(input []string) []string {
reg, err := regexp.Compile("[^a-zA-Z0-9_]+")
if err != nil {
fmt.Println("Error compiling regexp:", err)
return nil
}
var returnSlice []string
for _, thing := range input {
output := reg.ReplaceAllString(thing, "")
returnSlice = append(returnSlice, output)
}
return returnSlice
}
func matchRegexList(expressions []string, testStr string) bool {
for _, item := range expressions {
compiled, err := regexp.Compile(item)
if err != nil {
fmt.Println("Error compiling regexp", item)
fmt.Println(err.Error())
fmt.Println("Skipping.")
continue
}
if compiled.MatchString(testStr) {
return true
}
}
return false
}