2016-11-09 212 views
-2

我有一個包含兩個日期的文字,我想提取文本,這將是對這個文本的正則表達式兩個日期。正則表達式

he was out of city in period of 10/15/16 Sat 7am - 10/16/16 Sun 3am ₨350.00/hr - you have to remain onlines, which will enable you to meet him. 

我有多個不同文本的字符串,但每個字符串都有兩個日期。我如何在php中獲得這些日期。只是想日期16年10月15日和16年10月16日

+0

您是否嘗試過的東西? –

+0

這是什麼:'₨350.00/hr'?它應該匹配嗎? – nozzleman

回答

0

這應該讓你接近:

(0[1-9]|1[012])\/([0][1-9]]|[12]\d|3[01])\/\d{2}\s[A-Z][a-z]{2}\s(\d|1[012])[ap]m 

看到這個Action at Regex101

,如果你只想匹配有效日期:

(0[1-9]|1[012])\/([0][1-9]]|[12]\d|3[01])\/\d{2} 

this example

0

如果使用此拍它將捕獲格式x(x)/ x(x)/ xx(xx)。
含義一位或兩位數的日,月和兩個或四個數字的年份。

$string = "he was out of city in period of 10/15/2016 Sat 7am - 10/16/16 Sun 3am ₨350.00/hr - you have to remain onlines, which will enable you to meet him."; 
preg_match_all("/(\d{1,2}\/\d{1,2}\/\d{2,4})/", $string, $dates); 


var_dump($dates[1]);