-
-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
:
- Loading branch information
Showing
5 changed files
with
181 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ import ( | |
- [Rotate](#Rotate) | ||
- [TemplateReplace](#TemplateReplace) | ||
- [RegexMatchAllGroups](#RegexMatchAllGroups) | ||
- [ExtractContent](#ExtractContent) | ||
|
||
|
||
<div STYLE="page-break-after: always;"></div> | ||
|
@@ -1728,4 +1729,34 @@ func main() { | |
// [[email protected] john.doe example com] | ||
// [[email protected] jane.doe example com] | ||
} | ||
``` | ||
|
||
### <span id="ExtractContent">ExtractContent</span> | ||
|
||
<p>提取两个标记之间的内容。</p> | ||
|
||
<b>函数签名:</b> | ||
|
||
```go | ||
func ExtractContent(s, start, end string) []string | ||
``` | ||
|
||
<b>示例:<span style="float:right;display:inline-block;">[Run](todo)</span></b> | ||
|
||
```go | ||
import ( | ||
"fmt" | ||
"github.com/duke-git/lancet/v2/strutil" | ||
) | ||
|
||
func main() { | ||
html := `<span>content1</span>aa<span>content2</span>bb<span>content1</span>` | ||
|
||
result := strutil.ExtractContent(html, "<span>", "</span>") | ||
|
||
fmt.Println(result) | ||
|
||
// Output: | ||
// [content1 content2 content1] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,8 @@ import ( | |
- [Rotate](#Rotate) | ||
- [TemplateReplace](#TemplateReplace) | ||
- [RegexMatchAllGroups](#RegexMatchAllGroups) | ||
- [ExtractContent](#RegexMatchAllGroups) | ||
|
||
|
||
<div STYLE="page-break-after: always;"></div> | ||
|
||
|
@@ -1708,7 +1710,7 @@ func main() { | |
func RegexMatchAllGroups(pattern, str string) [][]string | ||
``` | ||
|
||
<b>example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/JZiu0RXpgN-)</span></b> | ||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/JZiu0RXpgN-)</span></b> | ||
|
||
```go | ||
import ( | ||
|
@@ -1729,4 +1731,34 @@ func main() { | |
// [[email protected] john.doe example com] | ||
// [[email protected] jane.doe example com] | ||
} | ||
``` | ||
|
||
### <span id="ExtractContent">ExtractContent</span> | ||
|
||
<p>Extracts the content between the start and end strings in the source string.</p> | ||
|
||
<b>Signature:</b> | ||
|
||
```go | ||
func ExtractContent(s, start, end string) []string | ||
``` | ||
|
||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b> | ||
|
||
```go | ||
import ( | ||
"fmt" | ||
"github.com/duke-git/lancet/v2/strutil" | ||
) | ||
|
||
func main() { | ||
html := `<span>content1</span>aa<span>content2</span>bb<span>content1</span>` | ||
|
||
result := strutil.ExtractContent(html, "<span>", "</span>") | ||
|
||
fmt.Println(result) | ||
|
||
// Output: | ||
// [content1 content2 content1] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -753,3 +753,15 @@ func ExampleRegexMatchAllGroups() { | |
// [[email protected] john.doe example com] | ||
// [[email protected] jane.doe example com] | ||
} | ||
|
||
func ExampleExtractContent() { | ||
html := `<span>content1</span>aa<span>content2</span>bb<span>content1</span>` | ||
|
||
result := ExtractContent(html, "<span>", "</span>") | ||
|
||
fmt.Println(result) | ||
|
||
// Output: | ||
// [content1 content2 content1] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters