1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-08 06:32:28 +08:00

feat: add ExtractContent

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

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
}