Regex for date (YYYY-MM-DD)
/\b\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])\b/g
Matches
Examples
Note
Checks month and day ranges but not the calendar: 2024-02-31 still matches. Parse the match with a date library to be sure.
Matches in the example
"2024-01-15""2024-12-31"
Token by token
\ba word boundary\d{4}a digit (0–9), exactly 4 times-the character “-”(?:a group, not capturing0the character “0”[1-9]one of: “1” to “9”|or1the character “1”[0-2]one of: “0” to “2”)end of group-the character “-”(?:a group, not capturing0the character “0”[1-9]one of: “1” to “9”|or[12]one of: “1” or “2”\da digit (0–9)|or3the character “3”[01]one of: “0” or “1”)end of group\ba word boundary
Other patterns
- Email address
- URL
- IPv4 address
- UUID
- Hex color
- Date (YYYY-MM-DD)
- Time (24-hour)
- US phone number
- Phone number (E.164)
- US ZIP code
- Credit card number
- URL slug
- Username
- Strong password
- HTML tag
- Semantic version
- MAC address
- JSON Web Token
- Hashtag
- @mention
- Number
- Leading and trailing whitespace
- Repeated word
- Blank lines
- Markdown link
- Quoted string
- Domain name
- File extension
- Base64
- Trailing comma