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 “


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

would have to return:

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"
Forming my string

resp, err := http.Get("")
	if err != nil {
	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 {

Here’s a working example in the playground:


I did not know about this package.
Thks so much.
It worked

1 Like

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