我正在製作一個腳本,經過大量電子郵件尋找兩個字符串。如何只在這個正則表達式中獲得一個匹配?
要麼它會找到been all shipped on [timestamp here]
或shipped by the seller on [timestamp here]
。
現在,我在$res[1]
上找到一個空匹配項,如果它只找到第二個字符串,並且在$res[2]
中爲空,如果它只找到第一個。我怎樣才能解決這個問題,所以它會一直填滿$res[1]
找到的時間戳?
if (preg_match("/been all shipped on ([0-9]{4}\.[0-9]{2}\.[0-9]{2} [0-9]{2}:[0-9]{2})|shipped by the seller on ([0-9]{4}\.[0-9]{2}\.[0-9]{2} [0-9]{2}:[0-9]{2})/", strip_tags($message), $res)) {
}
我們可以得到一些樣本數據(重要部分的片段),以便我們可以看到您的正則表達式是否正確? – dab