Go (RE2)

Keep-a-Changelog Entry Header in GO

Match Keep-a-Changelog style version headers like `## [1.2.3] - 2024-01-15` or `## 2.0.0`.

Try it in the GO tester →

Pattern

regexGO
^##\s+\[?([\w.\-]+)\]?(?:\s*-\s*(\d{4}-\d{2}-\d{2}))?   (flags: gm)

Go (RE2) code

goGo
package main

import (
	"fmt"
	"regexp"
)

func main() {
	re := regexp.MustCompile(`(?m)^##\s+\[?([\w.\-]+)\]?(?:\s*-\s*(\d{4}-\d{2}-\d{2}))?`)
	input := `## [1.2.3] - 2024-01-15\n## [Unreleased]`
	for _, match := range re.FindAllString(input, -1) {
		fmt.Println(match)
	}
}

Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.

How the pattern works

^## matches the markdown H2 marker. \s+ requires whitespace. \[? optionally matches an opening bracket. ([\w.\-]+) captures the version (semver, calendar version, or label like `Unreleased`). \]? optionally matches the closing bracket. (?:\s*-\s*(\d{4}-\d{2}-\d{2}))? optionally captures an ISO date.

Examples

Input

## [1.2.3] - 2024-01-15\n## [Unreleased]

Matches

  • ## [1.2.3] - 2024-01-15
  • ## [Unreleased]

Input

## 2.0.0 - 2025-12-25

Matches

  • ## 2.0.0 - 2025-12-25

Input

# Title

No match

Same pattern, other engines

← Back to Keep-a-Changelog Entry Header overview (all engines)