useful string manipulation functions
authorEduardo <[email protected]>
Thu, 28 Mar 2024 02:34:53 +0000 (03:34 +0100)
committerEduardo <[email protected]>
Thu, 28 Mar 2024 02:34:53 +0000 (03:34 +0100)
get text after dash, get first line and get requested by

bot.go

diff --git a/bot.go b/bot.go
index 31717cfa479c8c901485a5d8c7d211981da21076..d4b42925634fb2ffb3399c15dd544b55d8222ec8 100644 (file)
--- a/bot.go
+++ b/bot.go
@@ -445,3 +445,25 @@ func replaceAllStrings(str string, old []string, new string) string {
 
        return str
 }
+
+func getTextAfterDash(s string) string {
+       dashIndex := strings.Index(s, "-")
+       if dashIndex != -1 {
+               return strings.TrimSpace(s[dashIndex+1:])
+       }
+       return ""
+}
+
+func getFirstLine(s string) string {
+       lines := strings.SplitN(s, "\n", 2)
+       return lines[0]
+}
+
+func getRequestedBy(s string) string {
+       re := regexp.MustCompile(`(?i)Requested By:\s*(.*)`)
+       match := re.FindStringSubmatch(s)
+       if len(match) > 1 {
+               return strings.TrimSpace(match[1])
+       }
+       return "???"
+}