I am finally sitting down to start writing utilities using Go. The first one on my list is a utility that parses my broadband usage and displays how much bandwidth utilization I have left (MB remaining, % remaining and refill time).
I am successfully pulling the status page using net/http, the return from that is a horribly ugly web-page that I need to parse. I started using the regexp package to parse the output and can pull the string but there is a lot of text around also getting pulled (I just want the number for the percentage not the html tags surrounding).
Here is the text I am pulling. In this example only 67 should return as my percentage.
<td style="border-width:0px;">Allowance Remaining (%)</td><td style="border-width:0px;">67</td>
My regexp regex snippet:
pct_remaining_regex, err := regexp.Compile("(?:<td style=\"border-width:0px;\">Allowance Remaining \\(%\\)</td><td style=\"border-width:0px;\">([0-9]+)</td>)")
if err != nil {
log.Fatal(err)
}
pct_remaining := pct_remaining_regex.Find(allowance_req)
I tried to use capture groups but I am unsure how to use them properly in go. Using my snippet
pct_remaining = <td style="border-width:0px;">Allowance Remaining (%)</td><td style="border-width:0px;">67</td>
I also tried to use SubexpNames like below:
numSub := pct_remaining_regex.NumSubexp()
names := pct_remaining_regex.SubexpNames()
here numSub gets set to 1 as I would expect but both names[0] and names[1] are blank.
Any advice would be greatly appreciated.
---------------------------------
Derek Tracy
tra...@gmail.com---------------------------------