REGEXVAULTv2.0
Finance/Financial Formats
Verified Safe

Accounting Period (YYYY-MM) Regex for Go

/^((?:19|20)[0-9]{2})-(0[1-9]|1[0-2])$/

What this pattern does

This page provides a well-structured, multi-part regular expression for matching accounting period (yyyy-mm), ported and verified for Go. Financial data validation has zero tolerance for false negatives — a missed invalid entry can corrupt downstream calculations. The snippet below is ready to drop into your Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.

Go Implementation

Go
// Accounting Period (YYYY-MM)
// ReDoS-safe | RegexVault — Finance > Financial Formats

package validation

import "regexp"

var accountingPeriodYyyymmRe = regexp.MustCompile(`^((?:19|20)[0-9]{2})-(0[1-9]|1[0-2])$`)

func ValidateAccountingPeriodYyyymm(s string) bool {
    return accountingPeriodYyyymmRe.MatchString(s)
}

// Example
// fmt.Println(ValidateAccountingPeriodYyyymm("2024-01")) // true

Test Cases

Matches (Valid)
Rejects (Invalid)
2024-012024-00
2024-122024-13
1999-0624-01
2025-032024/01
2024-1
2024-012

When to use this pattern

This pattern is drawn from the Finance > Financial Formats category and carries a ReDoS-safe certification. That matters for Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

Fiscal year start varies by company and jurisdiction: US government FY starts October, Singapore FY starts April for many companies. Store fiscal year alongside calendar period.

Technical Notes

Capture group 1: year (1900-2099), group 2: month (01-12). Accounting periods usually follow calendar months but some companies use fiscal months not aligned to calendar months.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern