文字列の ZAMM レコードを取得する必要があります。スペースがある場合、それに属するデータをキャプチャできません。
私の文字列:
$string ='ZAMM Et a est hac pid pid sit amet, lacus nisi
ZPPP scelerisque sagittis montes, porttitor ut arcu
ZAMM tincidunt cursus eu amet nunc
ZAMM c ac nunc, et pid pellentesque amet,
ZSSS m urna scelerisque in vut';
期待リターン:
ZAMM Et a est hac pid pid sit amet, lacus nisi
ZAMM tincidunt cursus eu amet nunc
ZAMM c ac nunc, et pid pellentesque amet,
私は使用しています:
$arrayst = explode(" ", $string);
foreach($arrayst as $stringit) {
if(preg_match("/ZAMM.*/", $stringit, $matches)) {
echo $stringit;
echo "<br />";
}
}
// Return:
ZAMM
arcu ZAMM
nunc ZAMM
間違った正規表現を使用していますか?
編集:最後の質問。私の文字列が次のような場合:
$string ='ZAMM Et a est hac pid pid sit amet, lacus nisi ZPPP scelerisque sagittis montes, porttitor ut arcu ZAMM tincidunt cursus eu amet nunc ZAMM c ac nunc, et pid pellentesque amet, ZSSS m urna scelerisque in vut';