I have a HTML code as a golang string, out of which I want to extract a particular header, after the last occurence of a pattern. To explain with an example:
func main() {
h := `
<html>
<body>
<a name="0"> text </a>
<a name="1"> abc </a>
<a name="2"> def ghi jkl </a>
<a name="3"> abc </a>
<a name="4"> Some text </a>
</body>
</html>`
pattern := "abc"
// Now I want <a name="3"> to be printed. I mean, when someone
// searches for the pattern abc, the last occurence is the <a>
// section with the name "3". If the pattern is "def" then "2"
// should be printed, if the pattern is "text" then 4 should
// be printed
}
Any idea how I can do this ? I played around with the templates and the Scanner packages but could not get it working.