A
A
Artem2015-11-06 23:21:30
PHP
Artem, 2015-11-06 23:21:30

What is the best way to write a regular expression?

Hello.
There is the following line

"$cond($eq($HND,1),0.85*($m1*1.2*1.03*$MWS/100)+0.03*($MW+$mw)/2-1,1.2*($m1*1.2*1.03*$MWS/100)+0.03*($MW+$mw)/2+1)"

which is inside the text.
I need to correctly compose an expression in order to get the following values ​​(there may be different constructions inside "", but the essence of the regular expression is the same)
Array(
        [0] => array(
                          [0] => '$cond',
                          [1] => '$eq($HND,1)',
                          [2] => '0.85*($m1*1.2*1.03*$MWS/100)+0.03*($MW+$mw)/2-1,1.2*($m1*1.2*1.03*$MWS/100)+0.03*($MW+$mw)/2+1'
                          ),
        [1] => array(
                           [0] => '$eq',
                           [1] => '$HND',
                           [2] => '1'
                          )

Roughly speaking, to decompose the functions inside this construction into components

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zelimkhan Beltoev, 2015-11-07
@I7uoHep

Considering that other functions can be arguments, there is little you can do here with regular expressions (by the way, in your example Array[0][2] is not correct, since, logically, the string
should have gone to Array[0][3 ] as the third argument of the function)
Such a problem could be solved by the following algorithm:
It can be implemented both with recursion and with a simple loop. It seems that he painted everything intelligibly and did not miss anything

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question