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
Golang Get current Date and Time in EST, UTC and MST?
Example of Pointers with Struct
How to get struct variable information using reflect package?
How to read/write from/to file in Golang?
Different ways to validate JSON string
How to check if a string contains only letters in Golang?
Split a character string based on change of character
Regular expression for matching HH:MM time format in Golang
Golang Slice interface and array concatenation
How to use Ellipsis (...) in Golang?