Tuesday, 15 July 2014

javascript - How to match date in string -


I'm trying to tease a date with a block of text as far as I know, the date is always 5 March 2015 (three-letter month, no major zero, four-digit yearday).

The block of text is slightly more variable, though. For the most part, this usually looks like this:

We understand that sometimes your travel plans change, we do not charge any change or cancellation fee. However, this property (hotel name) imposes the following penalties to its customers that we need to pass it on: Cancellations or 11:59 AM (GMT-5: 00) made after Eastern Time (US and Canada) Change) 1 night room on 10th March 2015 & amp; Tax Fines

This is my attempt ( val is a string containing variable):

 var valDate = val.match ("\\\" ) \\\) but (. *) Are "); Return Validate [1]; 

As you can see, I am at the end of time (which I believe is always there, regardless of EST / PST / etc) and

< Block>

And it was working very well .... Until one of my hotels did the following:

We Understand that sometimes your travel plans change, we do not charge any change or cancellation fee. However, this property (hotel name) imposes the following penalties to its customers that we need to cancel or change before 6:00 pm (GMT-5: 00) Eastern Time (US and Canada) March 15, 2015 1 night room and tax fines March 15, 2015 (6:00 pm (GMT-05: 00) Cancellations or changes made after the Eastern Time (US and Canada) 1 night room and tax fines

15 March 2015 are subject to 1 night room and The property does not give any refund to the show or initial checkouts.

; Taxes tax on March 15, 2015 at 6:00 pm (GMT-05: 00) Eastern Time (US and US Canada) or

which is far less than desirable, I think I understand why this is happening but try but I am not deciding it Additionally, my original mail is validly silly (hence the problem). ). I think that's probably a better way to launch the on ... I do not know how. Can

Does anyone help me? I will be very grateful at all!

A pattern that can match the description you provided:

(January | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Dec | Dec) \ [+0-9] | [1-2] [0-9] | 3 [0-1]), \ s + \ d {4}

Although I'm sure if you want to capture dates, you better To do this Search for a library such a library is probably less error prone, al -Separate the date patterns and perhaps make it easier to customize.

You can capture the group as a show:

  var r = / (Jan | Feb | Mar | Apr | May | Jun | July | Aug | September | October | November | Dec) \ s + ([0-9] | [1-2] [0-9] | 3 [0-1]) \ s + \ d {4} / g; Var t = "We understand that sometimes your travel plans change, we do not make any changes or cancel the charges. However, this property (hotel name) imposes a low penalty to its customers Passing on: Cancellations or changes are subject to 1 night room and tax penalty after 10 March 2015 at 11:59 am ((GMT-5: 00) Eastern Time (US and Canada)) Property No Show or Initial Check out No refund is given for the purpose. "; M = r.exec (t); While (m! = Null) {// m [0] do something with warning (i [0]); // example m = r.exec (t); }  

.


No comments:

Post a Comment