Regular Expressions 101

Community Library Entry

2

Regular Expression
Java 8

"
^(((\d{3}[1-9]|\d{2}[1-9]\d|\d[1-9]\d{2}|[1-9]\d{3})(\/)(((0[13578]|1[02])(\/)(0[1-9]|[12]\d|3[01]))|((0[469]|11)(\/)(0[1-9]|[12]\d|30))|(02(\/)(0[1-9]|[1]\d|2[0-8]))))|(((\d{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))(\/)02(\/)29))$
"
gm

Description

^(((\d{3}[1-9]|\d{2}[1-9]\d|\d[1-9]\d{2}|[1-9]\d{3})(/)(((0[13578]|1[02])(/)(0[1-9]|[12]\d|3[01]))|((0[469]|11)(/)(0[1-9]|[12]\d|30))|(02(/)(0[1-9]|[1]\d|2[0-8]))))|(((\d{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))(/)02(/)29))$

Match year/month/day, date format. E.g: 2021/08/25 [match] 2021/09/30 [match] 2018/02/28 [match] 2024/02/29 [match] 2023/02/29 [mismatch]

Submitted by mayl0421 - 3 years ago