Regular Expressions 101

Community Patterns

Match any UK Date

0

Regular Expression
PCRE (PHP <7.3)

/
(?<=^|\s)(?<Day>0[1-9]|1[0-9]|2[0-9]|3[0-1]|[1-9])(?:st|nd|rd|th)?(?:\/| |-|\.)(?<Month>0[1-9]|1[0-2]|[1-9]|Jan|January|Feb|February|Mar|March|Apr|April|May|Jun|June|Jul|July|Aug|August|Sep|September|Oct|October|Nov|November|Dec|December)(?:-|\/| |\.)(?<Year>(?:[1-2]\d)?(?:\d\d))(?=\s)
/
gmi

Description

Finds any date in UK date format with or without century and allows for month names and abreviations as well as ordinal indicators (st, nd, rd, th)

This expression uses look behind and look ahead to ensure the date is either at the start of a line or preceeded by whitspace.

Submitted by anonymous - 6 years ago