package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)var\s(\w+)\s?\=\s?(\d+|\"[^\n"]*\"|\'[^\n']*\')\s?\;`)
var str = `<html>
<head>~~</head>
<body>
<div>contents</div>
<script>
var value1 = 55;var value2= 27;
var value3 = 'T';var value4 = "FIT#$%SIZE";
var value5 = '{\"P00000WJ000E\":{\"stock_price\":\"0.00\",\"use_stock\":true,\"use_soldout\":\"T\",\"is_display\":\"T\",\"is_selling\":\"T\",\"option_price\":79000,\"option_name\":\"FIT#$%SIZE\",\"option_value\":\"NOBLE-44\",\"stock_number\":26,\"option_value_orginal\":[\"NOBLE\",\"44\"],\"use_stock_original\":\"T\",\"use_soldout_original\":\"T\",\"use_soldout_today_delivery\":\"F\",\"is_auto_soldout\":\"F\",\"is_mandatory\":\"T\",\"option_id\":\"000E\",\"is_reserve_stat\":\"N\",\"item_image_file\":null,\"origin_option_added_price\":\"0.00\"}}';var value6 = '1';var value7 = 'string;must-catch';
var value8 = 8;
var value9 = 'S';
var value10 = 'T';
</script>
</body>
</html>`
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/