[thelist] javascript / regex conundrum

liorean liorean at gmail.com
Fri Oct 17 00:30:42 CDT 2008


2008/10/17 Jeremy Weiss <eccentric.one at gmail.com>:
> Here's a sample of what could be in that field:
>
> 1 - Date:10/18/2008, Time:1300-1600, Type:PUB, Comment: 2 - Date:10/19/2008, Time:1300-1600, Type:PUB, Comment:';

Not quite enough information on the possible values of Type and the
delimiters on Comment, so I can't give you a fully functional regex
for extracting all the variable date out of it, but here's a start:

    var
        re=/(\d+)\s-\sDate:(\d+)\/(\d+)\/(\d+),\sTime:(\d+)-(\d+),\sType:(PUB|whatever|whateverelse),\sComment:()/g,
        str='1 - Date:10/18/2008, Time:1300-1600, Type:PUB, Comment: 2
- Date:10/19/2008, Time:1300-1600, Type:PUB, Comment:',
        ra;
    while(ra=re.exec(str))
        alert('Number: '+ra[1]+'\nMonth: '+ra[2]+'\nDate:
'+ra[3]+'\nYear: '+ra[4]+'\nStart time: '+ra[5]+'\nEnd time:
'+ra[6]+'\nType: '+ra[7]+'\nComment: '+ra[8]);
-- 
David "liorean" Andersson



More information about the thelist mailing list