summaryrefslogtreecommitdiff
path: root/internal/entry/entry.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-10-24 10:25:00 +0300
committerPaul Buetow <paul@buetow.org>2024-10-24 10:25:00 +0300
commit9a68ca0461bdf6d093213a218fbf255678018a16 (patch)
treefb955dbeffd8d028c50652131ec9090982d9338b /internal/entry/entry.go
parentdde64be2724fd4e407315627943dd8dd37e5adf0 (diff)
move extract URLs to types.Entry
Diffstat (limited to 'internal/entry/entry.go')
-rw-r--r--internal/entry/entry.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/internal/entry/entry.go b/internal/entry/entry.go
index 99f7ee3..34ce5f0 100644
--- a/internal/entry/entry.go
+++ b/internal/entry/entry.go
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
+ "regexp"
"strings"
"time"
@@ -126,3 +127,15 @@ func (e Entry) Edit() error {
}
return nil
}
+
+// extractURLs finds all occurrences of URLs starting with "http://" or "https://" in a given string.
+func (e Entry) ExtractURLs() []string {
+ content, _ := e.Content()
+ return extractURLs(content)
+}
+
+func extractURLs(input string) []string {
+ urlPattern := `(http://|https://|ftp://)[^\s]+`
+ re := regexp.MustCompile(urlPattern)
+ return re.FindAllString(input, -1)
+}