Go (RE2)

European Date Format (DD/MM/YYYY) in GO

Match European-style dates in DD/MM/YYYY format with valid day (01–31) and month (01–12) ranges.

Try it in the GO tester →

Pattern

regexGO
(?:0[1-9]|[12]\d|3[01])\/(?:0[1-9]|1[0-2])\/\d{4}   (flags: g)

Go (RE2) code

goGo
package main

import (
	"fmt"
	"regexp"
)

func main() {
	re := regexp.MustCompile(`(?:0[1-9]|[12]\d|3[01])\/(?:0[1-9]|1[0-2])\/\d{4}`)
	input := `15/01/2024`
	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

Day alternation covers 01–31, month covers 01–12, year is any 4-digit number. Slashes are literal. Does not detect impossible combinations like 31/02/2024.

Examples

Input

15/01/2024

Matches

  • 15/01/2024

Input

31/12/1999

Matches

  • 31/12/1999

Input

32/01/2024

No match

Same pattern, other engines

← Back to European Date Format (DD/MM/YYYY) overview (all engines)