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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -