时间:2021-07-01 10:21:17 帮助过:5人阅读
$str = '{if aa eq bb or cc eq dd or ee eq ff}';
$patten = '/(?:if
------解决思路----------------------
or)\s+((\S+)\s+eq\s+([^ }]+))/';
preg_match_all($patten,$str,$patten_all);
var_dump($patten_all);
array(4) {
[0]=>
array(3) {
[0]=>
string(11) "if aa eq bb"
[1]=>
string(11) "or cc eq dd"
[2]=>
string(11) "or ee eq ff"
}
[1]=>
array(3) {
[0]=>
string(8) "aa eq bb"
[1]=>
string(8) "cc eq dd"
[2]=>
string(8) "ee eq ff"
}
[2]=>
array(3) {
[0]=>
string(2) "aa"
[1]=>
string(2) "cc"
[2]=>
string(2) "ee"
}
[3]=>
array(3) {
[0]=>
string(2) "bb"
[1]=>
string(2) "dd"
[2]=>
string(2) "ff"
}
}