InRegex Logo
InRegex
New

Match Dates in DD/MM/YYYY or DD/MM/YY Format

Explanation

This regex pattern matches dates in the format DD/MM/YYYY or DD/MM/YY. It breaks down as follows: - \b: Asserts a word boundary to ensure the whole date is matched. - (0[1-9]|[12][0-9]|3[01]): Matches the day part (01 to 31). - /(0[1-9]|1[0-2]): Matches the month part (01 to 12) after the day. - /(\d{4}|\d{2}): Matches the year part, either 4 digits for YYYY or 2 digits for YY. - \b: Ensures the date ends at a word boundary.

javascript

Regular Expression

\b(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/(\d{4}|\d{2})\b
Copy
Do you have Feedback?
javascript

Example Usage

const dateRegex = /\b(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/(\d{4}|\d{2})\b/;
Copy

Test the expression

Similar Regular Expressions