Add regex matching function to util

This commit is contained in:
2025-01-16 22:36:03 +02:00
parent 973a4f3a2d
commit b6dd77e57e
2 changed files with 18 additions and 6 deletions

View File

@@ -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
}