javascript - Match a character the same amount of times that a previous character has been matched -


i in need way interpret x ^ y (i aware there such solutions available, challenging myself go "library-free"). thought using regexp, such:

(\(*\w+\)*|\(*math.pow\(\w+,\w+\)\)*=*)+\s*\^\s*(\(*\w\)*)+\)* 

(http://regexr.com/3b0dl) , replace string "math.pow($1,$2)".

now, works cases i've tested far, save following:

1 - paren surrounding expression

(2 ^ (5)) 

which replaces thus:

math.pow((2,(5))) 

which evaluates (2,(5). there way can fix regexp matches ) many times matched ( in second catch group?

2 - multiple iteration

(2 ^ 3) ^ 5 

is replaced with

math.pow((2,3)) ^ 5 

which leaves unevaluated ^. figure may done while(input.match("^"){...} sort thing, want know if possible via regexp.


thank in advance help.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -