Python (re)

Keep-a-Changelog Entry Header in PY

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

Try it in the PY tester →

Pattern

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

Python (re) code

pyPython
import re

pattern = re.compile(r"^##\s+\[?([\w.\-]+)\]?(?:\s*-\s*(\d{4}-\d{2}-\d{2}))?", re.MULTILINE)
input_text = "## [1.2.3] - 2024-01-15\n## [Unreleased]"
for m in pattern.finditer(input_text):
    print(m.group(0))

Stdlib `re` module — no third-party dependency. Works on Python 3.6+.

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)