小编use*_*591的帖子

在Golang中从HTML中提取文本内容

在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)

regex string byte substring go

2
推荐指数
1
解决办法
4737
查看次数

标签 统计

byte ×1

go ×1

regex ×1

string ×1

substring ×1