package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^\s*[#%\/]*\s*(.*)[\n\r]`)
var str = `% x=(1:20)';
% y=randn(20,1);
% [bhat p wh se ci t_stat]=robust_fit(x,y,1);
% figure;plot(x,y,'.'); hold on; plot(x,bhat(1)+bhat(2).*x,'r')
% plot(x,[ones(length(x),1) x]*(([ones(length(x),1) x]'*[ones(length(x),1) x])\([ones(length(x),1) x]'*y)),'k')
% legend('Data','Robust','Non-robust')
`
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/