// Parse a changelog.md file and display changelog for a requested version
func Parse(match string, rem string) string {
// remove the enclosing pattern of previous release
temp := strings.TrimSuffix(match, rem)
return strings.Trim(temp, "\r\n")
enclosingPattern := `## [`
// prefixing verion number 0.6 with v won't work
// Every new version looks like this: ## [1.4.0] - Jan 12, 2069
// (?s) + <enclosing pattern> + <version-number> + .* + </enclosingPattern>
// (?s) : Make the dot match all characters including line break characters
// .* : . (dot) indicates any character whereas * specifies 0 or more instances of previous token
// var re = regexp.MustCompile(`(?s)## \[0.6.*?## \[`)
var re = regexp.MustCompile(`(?s)` + `## \[` + ver + `.*?` + `## \[`)
data, err := ioutil.ReadFile("CHANGELOG.md")
fmt.Println("File reading error", err)
fileContent := string(data)
submatchall = re.FindAllString(fileContent, 1)
if len(submatchall) == 1 {
fmt.Println(Parse(submatchall[0], enclosingPattern))
fmt.Println("No changelog or invalid version", ver)