パターンの最後の出現後に特定のヘッダを抽出したいgolang文字列としてHTMLコードがあります。例を説明する:Golangのパターンが最後に出現した後のHTMLテンプレートの解析ヘッダ
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
}
どのように私はこれを行うことができますか?私はテンプレートとスキャナーパッケージを使って遊んだが、動かすことができなかった。