REGEXP to get formatted date out of arbitrary length string

REGEXP string to get YYYY-MM-DD string from arbitrary length string

(19|20)dd([- /.])(0[1-9]|1[012])2(0[1-9]|[12][0-9]|3[01])

Example Matlab/Octave REGEXP date string

input = '09av8joj23oit2pojiijo/20398/vj89/2012-10-15/0298f9082j23'; %random stuff with date in it

regStr = '(19|20)dd([- /.])(0[1-9]|1[012])2(0[1-9]|[12][0-9]|3[01])';

[startIndex,endIndex] = regexp(input,regStr,'start','end')

myDate = input(startIndex:endIndex);

Tags:

Categories:

Updated: