regex - Pattern matching dates -


i'm having troubles trying match pattern of dates. of following dates legal:

 - 121212  - 4 9 12  - 5-3-2000  - 62502  - 3/3/11  - 09-08-2001  - 8 6 07  - 12 10 2004  - 4-16-08  - 3/7/2005 

what makes date matching challenging year doesn't have 4 digits (a 2 digit year assumed in 21st century i.e. 02 = 2002), month/date can either written beginning 0 if 1 digit month, , dates may or may not separated spaces, dashes, or slashes.

this have:
/((((0[13578])|([13578])|(1[02]))[\/-]?\s*(([1-9])|(0[1-9])|([12][0-9])|(3[01])))|(((0[469])|([469])|(11))[\/-]?\s*(([1-9])|(0[1-9])|([12][0-9])|(30)))|((2|02)[\/](([1-9])|(0[1-9])|([12][0-9])))[\/-]?\s*(20[0-9]{2})|([0-9]{2}))/g

this works, except right i'm not sure if i'm assuming length of dates , months. example, in case 121212, might assuming month 1 instead of 12. also, reason when i'm printing out $1 , $2, same value. in case of 121212, $1 1212, $2 1212 , $3 12. however, want $1 121212.

your task ambiguous, since may not able tell mmd mdd or mdccyy mmddyy.

you left off option spaces or dashes in 1 place match /.

you aren't checking leap years.

this doable, it's awfully easy make mistake; how not trying regex.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -