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
Replace numbers by zero from string
How to collect information about garbage collection?
Convert Float32 to Float64 and Float64 to Float32
Regular expression to extract text between square brackets
How to check lowercase characters in a string in Golang?
How to trim leading and trailing white spaces of a string in Golang?
Golang download image from given URL
How to check if a string contains certain characters in Golang?
Golang import package inside package
Example: Fields and FieldsFunc from BYTES Package