How to get multi-values using regexp

Good Night,
Somebody knows how to get multi-values using regexp.
For example, i have a string containing several lines, and i want to get all values that started with “

Exemple:

author, _ := regexp.Compile("<td>(.*?) ")

would have to return:
Teste1
Teste2
Teste3

Your post does not include any input data. Please check your usage of markup, maybe your data is just not visible to us because you’ve formated your question badly.

My string contains a html page, and i need get all values that started with "td"
Example:
Forming my string

resp, err := http.Get("http://www4.tjmg.jus.br/juridico/sf/proc_resultado.jsp?comrCodigo=479&numero=1&listaProcessos=01147778620178130479&btn_pesquisar=Pesquisar")
	if err != nil {
		log.Fatalln("Erro")
	}
	html, _ := ioutil.ReadAll(resp.Body)

My code regexep

author, _ := regexp.Compile("<td>(.*?) ")

I want get all values of the string html that I have td.

Sorry, my english not is very good

Why don’t you just parse the html and look for the tags? A slightly modified version of an example in the html package docs could suffice:

doc, err := html.Parse(r)
if err != nil {
	// ...
}
var f func(*html.Node)
f = func(n *html.Node) {
	if n.Type == html.ElementNode && n.Data == "td" {
		//Now do something with the inner text, like print it.
                fmt.Printf("<td> content is: %s\n", n.FirstChild.Data)
	}
	for c := n.FirstChild; c != nil; c = c.NextSibling {
		f(c)
	}
}
f(doc)

Here’s a working example in the playground: https://play.golang.org/p/SYTxumORJoT

2 Likes

Wooow,
I did not know about this package.
Thks so much.
It worked
:smiley:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.