2016-06-17 5 views
0

私のような文字列を持っています。正規表現は

だから、結果は配列でなければなりません:orange fruit, APPLE, Kiwi, banana pie

私は、私は非常に良いではないんだと正規表現を開始する場所がわからないんだけど。これを行う簡単な方法はありますか?あなたの現在の場合

答えて

1

は、次の手順を実行します

$string =' (orange fruit OR APPLE) AND (Kiwi OR banana pie)'; 
// Remove all extra characters and spaces from string 
$result = trim(preg_replace('#[\s\(\)]+#', ' ', $string)); 
// Split result by possible delimeters 
$result = preg_split('# (or|and) #i', $result); 
// Output 
print_r($result); 

出力:

Array (
    [0] => orange fruit 
    [1] => APPLE 
    [2] => Kiwi 
    [3] => banana pie 
)