package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?ims)<a[^>]*href="[^"]*(?<id>(?<=-)\d+)[^>]*>(?<name>[^<]*)</a`)
var str = `<div id="breadcrumbs" class="col-xs-12"> <div class="col-xs-9 no_padding "> <a href="/">Home</a> › <a href="http://www.mudah.my/Pahang/for-sale" itemprop="url" title="See all ads in Pahang"> Pahang </a> › <a href="http://www.mudah.my/Pahang/Shoes-for-sale-4160" itemprop="url" title="See all ads in Shoes category">Shoes</a> › Nike AIr Presto Khaki </div> <div class="col-xs-3 no_padding "> <div class="prev-next"> <span class="nohistory"> <a href="http://www.mudah.my/Pahang/nike+air-for-sale?fs=1&lst=0&so=1&q=nike+AIR">Back to Results</a> </span> <span class="thin_pipe">|</span> <span class="nohistory"> <a id="go_next" href="http://www.mudah.my/Nike+AIr+Presto+Khaki-52071755.htm?st=s&cg=0&q=nike+AIR&lst=0&fs=1&w=107&cg=0&q=nike+AIR&so=1&st=s&ca=7_s&next=1">Next Ad»</a> </span> </div> </div> </div>`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/