I need to create a Regular Expression (in Javascript) that will match a specific sentence structure. In my case, it's "Course ### day ###", where ### can be any 1 to 3 digit number. Additionally, it can be "week" instead of "day", so "Course ### week ###" is also valid.
So far, I've come up with:
var regTest=/^(Course) \d{1,3} (day)|(week) \d{1,3}$/
The problem is that this expression matches "Course 9 day 1", which is what I want, but it would also match "Course 9 day 1 scheduled on 07/01/09".
In other words, the following returns a value of 0:
"Course 9 day 1".search(regTest)
But this one also returns 0:
"Course 9 day 1 scheduled on 07/01/09".search(regTest)
I want the first test to return 0, but I want the second one to return -1. I need the expression to ONLY match up until the ### following day/week. How do you make it to stop at that point?