2016-04-04 30 views
1

刪除所有日期時間的正則表達式我有串與SWIFT新線路是這樣的:從談話

我怎樣才能把這個字符串的所有時間戳(2016年3月11日22時46分16秒)?

回答

0

最簡單的一個可以用以下正則表達式搜索並替換爲empty string

正則表達式:^[\d.: ]+:並替換爲empty string

Regex101 Demo

+0

你看到'evet dahamantıklı'在你的方法?它也匹配':D'。將它綁定到開始! – Jan

+0

@Jan:完成!謝謝。 –

0

最簡單的方法將是一個字符類與錨相結合:

^[\d. :]+(.+) 
# anchor it to the beginning of the line 
# only digits, spaces, dots and a colon allowed 
# one or more times 
# the (.+) brings you down the line 

僅取第一個捕獲組在這裏。
看到一個演示這種方法here on regex101.com

0

用最少的錯誤匹配最準確的解決辦法是這樣的:

^\d{2}.\d{2}.\d{4} \d{2}.\d{2}.\d{2}:

你需要使用正則表達式多和全局標誌太。