0

I have text input like this

input:

function1( param1,param2, function2 (param1,function3(param1)),fun())

I want to parse out data like this:

fun()

function3(param1)

function2(param1,function3(param1))

function1( param1,param2, function2 (param1,function3(param1)),fun())

basically i need to find each individual function with parameters.

i tried using Regex \w+\s?\(.*\) but it is giving me only this

function1( param1,param2, function2 (param1,function3(param1)),fun()).

juharr
  • 31,741
  • 4
  • 58
  • 93
Techie
  • 15
  • 4
  • 1
    Regex is not the best when dealing with multiple levels of nesting like this. You might want to simply look at writing a parser or finding an existing one that handles this for you. https://stackoverflow.com/questions/133601/can-regular-expressions-be-used-to-match-nested-patterns – juharr Aug 01 '19 at 14:42
  • Recursively unwrap functions and parse them. `const unWrap = s => s.replace(/\w+?\(\s*/, '').replace(/\)\s*$/, '')` – Xaqron Aug 01 '19 at 15:23
  • Thanks, I think unwrapping is the only way to extract all the functions from the string. – Techie Aug 02 '19 at 08:49

0 Answers0