RegEx For Finding DOB In A String Of Six Contiguous Numbers (mmddyy) -
sorry in advance if repeat question. didn't see listed elsewhere.
i'm trying find regex string recognize date of birth in format of mmddyy. far know though, regex doesn't know individual number sets begin/end if they're right next 1 another.
is there simple way regex find (without requiring delimiters/spacing)?
how like:
^([0-9]{2})([0-9]{2})([0-9]{2})$
the first group 2 digits month, next group 2 day, , last group year.
if wanted smarter, make sure first group starts 0 or 1, , day should start 0, 1, 2 or 3. perhaps:
^([0-1][0-9])([0-3][\d])([\d]{2})$
you might not need use regex if don't want to. every single modern framework these days (python, .net, java, whatever) has libraries , methods parse dates in specified format. have added benefit of type checking , ability build native date object well.
update:
you use or verify day doesn't go on 31:
^([0-1][0-9])([0-2][\d]|[3][0-1])([\d]{2})$
Comments
Post a Comment