'Use RegEx to find multiple occurences of the pattern
I got this string:
if(conditionA==valueA-AND-conditionB==valueB-OR-conditionC==valueC)
and I want an array that contains:
array(3) {
[0]=>
string(...) "conditionA==valueA"
[1]=>
string(...) "conditionB==valueB"
[2]=>
string(...) "conditionC==valueC"
}
I am currently using this pattern:
preg_match("/^if\((.+)-(.+)\)/U", $current_step_data_exploded[0], $if_statements);
but it doesn't deliver the third condition properly. Can somebody help me?
Solution 1:[1]
$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.";
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Musa |
