[thelist] javascript / regex conundrum

Vijay Immanuel codelad at gmail.com
Fri Oct 17 02:50:15 CDT 2008

If 'Type:' always follows the 'Time:' segment, you could use
look-ahead assertions to grab the time value alone:

var s = 'Date:10/18/2008, Time:1300-1600, Type:PUB, Comment: 2 -
Date:10/19/2008, Time:1300-1600, Type:PUB, Comment:';

var res = s.match(/([0-9\-]{9})(?=, Type:)/g);


On Fri, Oct 17, 2008 at 9:55 AM, Jeremy Weiss <eccentric.one at gmail.com> wrote:
> I have a page that is currently displaying information on when an open house is scheduled. Unfortunately everything (date, time, comments, etc.) is in a single field. And there's no limit on how many events may be in the field. The client is wanting me to change the time values from 24 hour to 12 hour. And due to a long list of factors that I can't change, I have to do this in JavaScript.
> 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:';
> Now, if I can get the '1300-1600' into a variable of its own, I can convert it. But I'm not sure how to pull it out or how to put the new value back. What I'm thinking is to do some regex magic to find all occurrences of "Time:" followed by "," and grab whatever is between them. Does that sound right? If so, I need help on the regex. I can find occurrences of "Time:" but I'm not sure how to grab only what follows it up to the next comma (without grabbing 'time:' or the comma).
> -jeremy
> --
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !

More information about the thelist mailing list