Q:

RegEx to extract parenthesis and function name

Somebody help me to write RegEx for the following cases

somestring() => ['somestring']
somestring()[10] => ['somestring','',10]
somestring('argString') => ['somestring', 'argString']
somestring('argString')[10] =>['somestring', 'argString',10]
somestring({prop1:'v1',prop2:'v2'}) => ['somestring', {prop1:'v1',prop2:'v2'}]
somestring({prop1:'v1',prop2:'v2'})[100] => ['somestring', {prop1:'v1',prop2:'v2'},100]

This is I tried so far 
var regExp = /\b[^()]+\((.*)\)+\[(.*?)]/;
var matches = regExp.exec('somestring()[10]');

A:

That could work:
var input = ['somestring()', 'somestring()[10]', "somestring('argString')", "somestring('argString')[10]", "somestring({prop1:'v1',prop2:'v2'})", "somestring({prop1:'v1',prop2:'v2'})[100]"];

console.log(input.map(function(v) {
  let result = v.match(/(.*)\((.*)\)(\[([^\]]*)\])?/);

  return [result[1], result[2], result[4]];
}));

