ホームページ  >  に質問  >  本文

正規表現を使用して、パターンの複数の出現を検索します。

次の文字列を取得しました:

if(条件 A== 値 A-AND-条件 B== 値 B-OR-条件 C== 値 C)

次の内容を含む配列が必要です:

配列(3) {
  [0]=>
  string(...) "条件A==値A"
  [1]=>
  string(...) "条件B==値B"
  [2]=>
  string(...) "条件C==値C"
}

現在このパターンを使用しています:

preg_match("/^if\((. )-(. )\)/U", $current_step_data_exploded[0], $if_statements);

しかし、これは 3 番目の条件を正しく満たしていません。誰か助けてくれませんか?

P粉186017651P粉186017651208日前3579

全員に返信(1)返信します

  • P粉139351297

    P粉1393512972024-02-27 21:14:22

    $string = "if(conditionA==valueA-AND-conditionB==valueB-OR-conditionC==valueC)";
    $match = preg_match('/^if\((.+)\)$/', $string, $if);
    if ($match) {
      $conditions = preg_split('/\-(AND|OR)\-/', $if[1]);
      print_r($conditions);
    } else {
      echo "no matches.";
    }

    返事
    0
  • キャンセル返事