我遇到了這個正則表達式的麻煩。 (https://regex101.com/r/vQLlyY/1)preg_match模式與斜線存儲在變量
我的模式工作,是:
(?<=Property:)(.*?)(?= \(Contact)|(?<=Property:)(.*?)(?= -)
你會在該屬性的文本在這兩個字符串所抽取的鏈接見:
Property: This is the property (Contact - Warren)
Property: This is another property - Warren
在我代碼,這種模式像這樣存儲:
$this->rex["property"][2] = '/(?<=Property:)(.*?)(?= \(Contact)|(?<=Property:)(.*?)(?= -)/s'
然後,提取這樣的:
foreach ($this->rex as $key => $value) {
if (isset($value[$provider])) {
preg_match_all($value[$provider], $emailtext, $matches);
if (!empty($matches[1][0])) {
$emaildetails[$key] = trim(preg_replace("/\r|\n/", "", $matches[1][0]));
} else {
$emaildetails[$key] = "";
}
}
}
在這個例子中,$提供商= 2
我的問題,我敢肯定,是與blackslash,因爲我不能得到這個代碼皮卡(Contact
這是我需要擺脫括號的模式的一部分。我知道代碼的工作原理,因爲我使用了許多其他模式。此外,這個工程的屬性文本如果模式存儲這樣的:
$this->rex["property"][2] = '/(?<=Property:)(.*?)(?= -)/s
所以,我在正確的存儲上的花紋都逃脫支架,或者是,即使我的問題嗎?提前致謝!
你可以澄清,如果你想捕捉「聯繫」或只是用它來匹配? –
只是匹配 - 我會'(聯繫「下面的屬性 – Warren
對不起,我仍然試圖瞭解你最終的結果,我在這個編輯器中包裝你的示例代碼:http://sandbox.onlinephpfunctions。 com/code/6a566fb5a0c6789d75a5fca24e4a6518cb1af561。請更新您的答案,並輸出您期望的print_r。 –