From 9a68ca0461bdf6d093213a218fbf255678018a16 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 24 Oct 2024 10:25:00 +0300 Subject: move extract URLs to types.Entry --- internal/entry/entry.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'internal/entry/entry.go') 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) +} -- cgit v1.2.3