Community Patterns

1

Date - Extract & Validate - Fully tested - Format YYYY-MM-DD (dynamic parts separator / can use a different separator)

Created·2020-11-20 19:31
Flavor·ECMAScript (JavaScript)
A fully tested regex that extracts and validates date parts using named capturing groups. \ Validations: Year must be preceded by nothing or a non-digit character Year must have 4 digits Month must be between 01 and 12 Month must have 2 digits Day must be between 01 and the maximum number of days for the month (e.g. february can't have more than 29 days) Day must have 2 digits Day must be followed by nothing or a non-digit character Separator must be any single character that is not a space or an alphanumeric character Separator must be the same between each date part \ Capturing groups: | # | Name | Description | |:-:|:-------:|-------------------------------------| | 1 | year | 4 digits of the year | | 2 | sep | Date parts separator | | 3 | month | 2 digits of the month | | 4 | day | 2 digits of the date (day of month) | \ Example usage: let match = regex.exec('2020-11-22') console.log('year: %s, month: %s, day: %s', match.groups.year, match.groups.month, match.groups.day) // year: 2020, month: 11, day: 22 \ Compatibility: (updated 2020-11-20) Chrome >= 64 Edge >= 79 Firefox >= 78 IE incompatible (lookbehind assertions & named capture groups not supported) Opera >= 51 Safari incompatible (lookbehind assertions not supported) NodeJS >= 10.0.0 See regex compatibility table. \ Note: does not validate leap years (not really possible in regex)
Submitted by Elie Grenon (DrunkenPoney) <elie.grenon.1@gmail.com>

Community Library Entry

0

Regular Expression
Created·2023-03-07 20:17
Updated·2025-12-18 05:34
Flavor·PCRE2 (PHP)

/
[[:ascii:]]+
/
g
Open regex in editor

Description

# 1. Type = xhr Response Headers access-control-allow-headers DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,X-DEVICE-TOKEN,deviceToken,agent access-control-allow-methods * access-control-allow-origin * access-control-expose-headers * access-control-max-age = 1728000 content-encoding = gzip content-type = application/json; charset = utf-8 date = Sat, 11 Feb 2023 04:29:06 GMT etag = W/"73d-UJDAIM5iwCpHWdETiOapCk02sEI" server = APISIX/2.13.0 strict-transport-security max-age=31536000; includeSubdomains; vary Accept-Encoding x-powered-by Express Request Headers Accept application/json, text/plain, / Response = { "result": 0, "message": "Success", "data": { "contracts": {"router": { "ETH": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39", "HECO": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39", "BSC": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39", "MATIC": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39", "TRON": "TKqQ7zuL7yKp1NWuhGpoXTDiE3j2qiAbRE", "FTM": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39", "OEC": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39", "ARB": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39", "KLAY": "0x9865EeBdD1cE65f45b6247AEEd2fA2252ECA7A08", "AVAX": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39", "KCC": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39", "CFX": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39", "GLMR": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39", "OP": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39", "ETC": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39" }, "approve": { "ETH": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39", "HECO": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39", "BSC": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39", "MATIC": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39", "TRON": "TKqQ7zuL7yKp1NWuhGpoXTDiE3j2qiAbRE", "FTM": "0xb45A2DDA996C32E93B8c47098E90Ed0E7ab18E39",

Submitted by Yetaroo