I am developing a parser in PHP and I need a functional Regular Expression to validate a string that contains a function.
Just to understand, that I will consider using preg_replace_callback
and create_function
to execute the function and replace value in string recursively;
Example of string: 15 + func1 ("gis", 22, func (55), 87) + 95 + func2 () + 35
The regex should be able to marry all the functions func1
and join func 2
. The regex (([^ ()])+([ ]?)*\(.*\))*
is outputting func1 ("gis", 22, func (55), 87) + 95 + func2 ()
as only a function. This is wrong because the "95" is out of any of the functions. The regex must also be able to deal with functions such as roles within in func1.
Appreciate any help.