I am trying to split the following expression into each array so that I can use the shunting yard algorithm to convert into postfix and evaluate later on. Here is the part of the string.
$string = '(fld_1010=="t" or fld_1010 != "test") and fld_1012 >= "18"
I am using the following pattern
$pattern = "/([\(|\s]*)(fld_)([0-9]*)[\s]*(!=|==|>=|<=|=|>|<|like|in)(.*?)([\)|\s]*)( and| or|\z)/";
$found preg_match_all($pattern , $string , $result,PREG_SET_ORDER);
print_r($result);
But I got this output :
[
[
"(fld_1010==\"t\" or",
"(",
"fld_",
"1010",
"==",
"\"t\"",
"",
" or"
],
[
" fld_1010 != \"test\") and",
" ",
"fld_",
"1010",
"!=",
" \"test\"",
")",
" and"
],
[
" fld_1012 >= \"18\"",
" ",
"fld_",
"1012",
">=",
" \"18\"",
"",
""
]
]
How could I split a string like this?
[
"(",
"fld_1010",
"==",
"t",
"or",
"fld_1010",
"!=",
"test",
")",
"and",
"fld_1012",
">=",
"18"
]
I am following this link but it only applies to mathematical expression with numbers only.
Thank you.