I'm trying to tease out a date from a block of text. As far as I know, the date will always look similar to Mar 5, 2015
(three-letter month, day with no leading zeros, four-digit year).
The block of text is a little more variable, however. For the most part, it looks generally like this:
We understand that sometimes your travel plans change. We do not charge a change or cancel fee. However, this property (Hotel Name) imposes the following penalty to its customers that we are required to pass on: Cancellations or changes made after 11:59 AM ((GMT-05:00) Eastern Time (US & Canada)) on Mar 10, 2015 are subject to a 1 Night Room & Tax penalty. The property makes no refunds for no shows or early checkouts.
Here's my attempt (val
is the variable containing the string):
var valDate = val.match("\\\)\\\) on (.*)are"); return valDate[1];
As you can see, I went for the two )) at the end of the timezone (which I believe will always be there, regardless of EST/PST/etc) and the 'are' that immediately follows the date.
And this was working very well.... until one of my hotels passed the following:
We understand that sometimes your travel plans change. We do not charge a change or cancel fee. However, this property (Hotel Name) imposes the following penalty to its customers that we are required to pass on: cancellations or changes made before 6:00 PM ((GMT-05:00) Eastern Time (US & Canada)) on Mar 15, 2015 are subject to a 1 Night Room & Tax penalty. Cancellations or changes made after 6:00 PM ((GMT-05:00) Eastern Time (US & Canada)) on Mar 15, 2015 are subject to a 1 Night Room & Tax penalty. The property makes no refunds for no shows or early checkouts.
And my code returned:
Mar 15, 2015 are subject to a 1 Night Room & Tax penalty. Cancellations or changes made after 6:00 PM ((GMT-05:00) Eastern Time (US & Canada)) on Mar 15, 2015
Which is somewhere less than desirable. I think I understand why this is happening, but try though I might I'm not fixing it. Additionally, my original match
is admittedly fumbly (hence this problem). I'm guessing there's probably a better way to tease out the date... I just have no idea how.
Can someone help me? I will be ever so grateful!