1

I have the following JavaScript RegEx to match functions prefixed by theme-.

/(theme-([\w-]+))(?:\s*\(\s*)([^)]+?)(?:\s*\))/gm

However, I also need to match other functions as parameters, like theme-foo(param1, theme-bar(arg1)), param3), but this RegEx isn't working because it assumes that the closing parentheses of the function being called in a parameter is the closing parentheses of the main function.

RegEx Example with the issue

How can I do this?

oscarmarcelo
  • 91
  • 1
  • 7

1 Answers1

0

How about follow:

let s = `theme-foo(param1, theme-bar(arg1), param3)`;
let regex = /([\w-]+(\(\w+\))?)/g;
let result = [];
s.replace(regex,function(match,param){
    result.push(param);
});
console.log(result);
protoproto
  • 2,081
  • 1
  • 13
  • 13