0

I have the following string:

01/12/2015-04/27/2015 Lecture Monday, Wednesday, Friday 12:00PM - 12:50PM, CoolGuy Hall, Room 006 01/12/2015-04/27/2015 Laboratory Thursday 10:50AM - 12:05PM, Epic Science, Room 121

I am trying to parse it so I can get objects like so

{
 days: ["Monday", "Wednesday", "Friday"]
 start: "12:00PM"
 end: "12:50PM"
 location: "CoolGuy Hall, Room 006"
}

and

{
 days: ["Thursday"]
 start: "10:50AM"
 end: "12:05PM"
 location: "Epic Science, Room 121"
}

Is there anyway to do this cleanly? I have tried using the split method using the dates:

/((..\/..\/....)-(..\/..\/....) \w+)/

to no avail and as you can see above my regex skills are fairly limited.

Thank you!

1 Answer 1

2

Following code is working for me... check is this you are trying to do...??

var data = "01/12/2015-04/27/2015 Lecture Monday, Wednesday, Friday 12:00PM - 12:50PM, CoolGuy Hall, Room 006 01/12/2015-04/27/2015 Laboratory Thursday 10:50AM - 12:05PM, Epic Science, Room 121"

data.replace(/\d{2}\/\d{2}\/\d{4}\-\d{2}\/\d{2}\/\d{4} ([^\s]+) ([^\d]+) ([^\s]+) \- ([^,]+), ([^,]+), Room ([^\s]+)/g, "{\n\tdays: [$2]\n\tstart: \"$3\"\n\tend: \"$4\"\n\tlocation: \"$5, Room $6\"\n}\n");

Output:

{
    days: [Monday, Wednesday, Friday]
    start: "12:00PM"
    end: "12:50PM"
    location: "CoolGuy Hall, Room 006"
}
{
    days: [Thursday]
    start: "10:50AM"
    end: "12:05PM"
    location: "Epic Science, Room 121"
}

Feel free to comment if you have any further questions or face difficulties to understand any part of my code...

Sign up to request clarification or add additional context in comments.

1 Comment

Holy f***, Thank you regex wizard! I wish I could give you more than one upvote

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.