How to extract text from between html tag using Regular Expressions in Golang?
Example
package main
import (
"fmt"
"regexp"
)
func main() {
str1 := `<html><body>
<form name="query" action="http://www.example.net/action.php" method="post">
<textarea type="text" name="nameiknow">The text I want</textarea>
<div id="button">
<input type="submit" value="Submit" />
</div>
</form>
</body></html>`
re := regexp.MustCompile(`<textarea.*?>(.*)</textarea>`)
submatchall := re.FindAllStringSubmatch(str1, -1)
for _, element := range submatchall {
fmt.Println(element[1])
}
}
Output
The text I want
Most Helpful This Week
How to create Map using the make function in Go?
Example: ReadAll, ReadDir, and ReadFile from IO Package
Example of Switch Case with Break in For Loop
Closures Functions in Golang
Simple function with parameters in Golang
How to collect information about garbage collection?
How to declare empty Map in Go?
Regular expression for matching HH:MM time format in Golang
Golang Read Write and Process data in CSV
Simple function with return value in Golang