Add regex matching function to util
This commit is contained in:
10
util/util.go
10
util/util.go
@@ -5,11 +5,12 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"regexp"
|
||||
"runtime/debug"
|
||||
)
|
||||
|
||||
func PrintStackAndPanic(err error) {
|
||||
fmt.Printf("Error %s Stack trace:\n%s", err, debug.Stack())
|
||||
fmt.Printf("PANIC Error %s Stack trace:\n%s", err, debug.Stack())
|
||||
panic("PANIC")
|
||||
}
|
||||
|
||||
@@ -34,3 +35,10 @@ func PrettyJson(data string) string {
|
||||
marshalled, _ := json.MarshalIndent(data, "", " ")
|
||||
return fmt.Sprintf("%s\n", marshalled)
|
||||
}
|
||||
|
||||
// GetLinesMatchingRegex returns all lines that match given regex
|
||||
func GetLinesMatchingRegex(input string, pattern string) []string {
|
||||
re := regexp.MustCompile(pattern)
|
||||
matches := re.FindAllString(input, -1)
|
||||
return matches
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user