feat: add ExtractContent

:
This commit is contained in:
dudaodong committed 2024-11-08 14:11:25 +08:00
1 parent 0ed2b11ba1
commit 08f14d2b08
5 files changed
+181 -1

No files matched your search

+21
View File
@@ -735,3 +735,24 @@ func RegexMatchAllGroups(pattern, str string) [][]string {
matches := re.FindAllStringSubmatch(str, -1)
return matches
}
// ExtractContent extracts the content between the start and end strings in the source string.
// Play: todo
func ExtractContent(s, start, end string) []string {
result := []string{}
for {
if _, after, ok := strings.Cut(s, start); ok {
if before, _, ok := strings.Cut(after, end); ok {
result = append(result, before)
s = after
} else {
break
}
} else {
break
}
}
return result
}