javascript - JS reg ex for month date -


i'm using simple indx uses js regex. %date% variable same regex

    (((j(anuary|uly|une))|february|(m(arch|ay))|(a(pril|ugust))|((sept|nov|dec)ember)|october)|     (jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec))[.,]{0,1}[\s]{0,1}[0-9]{1,2}[.,]{0,1}[\s]{0,1}(19|20|)\d\d|      (0[1-9]|[12][0-9]|3[01]|[1-9])(th|rd|st|nd){0,1}[\s]{0,1}(day\s){0,1}(of\s){0,1}(((j(anuary|uly|une))|february|     (m(arch|ay))|(a(pril|ugust))|((sept|nov|dec)ember)|october)|(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec))[.,]{0,2}       [\s]{0,1}(19|20|)\d\d| (0[1-9]|1[012]|[1-9])[- /.](0[1-9]|[12][0-9]|3[01]|[1-9])[- /.](19|20|)\d\d|(0[1-9]|      [12][0-9]|3[01]|[1-9])[- /.](0[1-9]|1[012]|[1-9])[- /.](19|20|)\d\d|(19|20|)\d\d[- /.](0[1-9]|1[012]|[1-9])[-        /.](0[1-9]|[12][0-9]|3[01]|[1-9]) 

but doesn't work. need have capture dates in numbers or numbers , month name have far, can't seem figure out how capture 5 may 2012

for nummeric dates

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

for month name (but incomplete. should i.e 5 may 2012)

(?<month>((jan(uary)?)|(feb(ruary)?)|(mar(ch)?)|(apr(il)?)|(may)|(june?)|(july?)|(aug(ust)?)|(sep(t(ember)?)?)|(oct(ober)?)|(nov(ember)?)|(dec(ember)?)))\s*[ ,-]\s*(?<date>(([12][0-9]) 

can advice

here (more understandable, hope) regex works cases yours:

var monthswords = "(jan(uary)?|feb(ruary)?|mar(ch)?|apr(il)?|may|june?|july?|aug(ust)?|sep(tember)?|oct(ober)?|nov(ember)?|dec(ember)?)"; var monthsnos = "((0?[1-9])|1[0-2])"; var months = "(("+monthswords+")|("+monthsnos+"))"; var days = "((0?[1-9])|([12][0-9])|(3[0-1]))"; var years = "\\d{4}"; var separator = "[. /-]"; var pattern = months + separator + days + separator + years; var regexp = new regexp(pattern, "i"); regexp.compile(regexp);  var result=regexp.test("may 4 2012"); 

of course, if need more flexibility (e.g. reverserd order of months , days) need modify pattern. also, assumed 4 digit string valid year, might need modify well. note use of "i" flag make pattern case insensitive.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -