在Golang中从字符串中提取内部子串的最佳方法是什么?
输入:
"Hello <p> this is paragraph </p> this is junk <p> this is paragraph 2 </p> this is junk 2"
Run Code Online (Sandbox Code Playgroud)
输出:
"this is paragraph \n
this is paragraph 2"
Run Code Online (Sandbox Code Playgroud)
是否有任何字符串包/库已经做了类似的事情?
package main
import (
"fmt"
"strings"
)
func main() {
longString := "Hello world <p> this is paragraph </p> this is junk <p> this is paragraph 2 </p> this is junk 2"
newString := getInnerStrings("<p>", "</p>", longString)
fmt.Println(newString)
//output: this is paragraph \n
// this is paragraph 2
} …Run Code Online (Sandbox Code Playgroud)