從Golang中的字符串中提取內部子字符串的最佳方式是什麼?在Golang中從HTML中提取文本內容
輸入:
"Hello <p> this is paragraph </p> this is junk <p> this is paragraph 2 </p> this is junk 2"
輸出:
"this is paragraph \n
this is paragraph 2"
是否有圍棋任何字符串包/庫已經做這樣的事情?
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
}
func getInnerStrings(start, end, str string) string {
//Brain Freeze
//Regex?
//Bytes Loop?
}
感謝
[Here](http://golang.org/pkg/regexp)。閱讀關於子匹配的部分;它應該幫助你。 – tenub
是的,我看到了,但我不確定這是否是正確的選擇。儘管爲未來引用添加書籤。 – user3173591