2017-02-26 109 views
0

我需要一個正則表達式將從字符串中刪除這類日期,例如:正則表達式此日期格式:日年月日時間的TimeZone

星期六2017年2月25日15.37 EST

+0

是否有一個很好的理由,你爲什麼會想這樣做的正則表達式? –

+0

@SeanF我正在做一些文本/句子過濾,這些日期是多餘的,不添加任何東西。如在線,來自在線新聞文章和whatnot。 –

回答

1

這將是一個位長。它會像55:32那樣奇怪的小時匹配,但我希望在這種情況下無關緊要。

/(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday)\s\d{1,2}\s(January|February|March|April|May|June|July|August|Septemper|Obctober|November|December)\s\d{4}\s\d{1,2}\.\d{2}\sEST/ 

var txt = document.getElementById('txt'); 
 

 
var reg = /(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday)\s\d{1,2}\s(January|February|March|April|May|June|July|August|Septemper|Obctober|November|December)\s\d{4}\s\d{1,2}\.\d{2}\sEST/g; 
 

 
var newTxt = txt.innerHTML.replace(reg,""); 
 
txt.innerHTML += "<p>"+newTxt+"</p>";
<p id="txt">lets say that we've got some string with some date Saturday 25 February 2017 15.37 EST just here and also here Monday 5 December 2005 3.37 EST and here Friday 13 March 2018 12.12 EST as well.</p>

相關問題