I want a regex to grab the arguments of RegExp
without parsing the code.
RegExp(/a+b/) Output: /a+b/
RegExp(/a+b/, 'g') Output: /a+b/, 'g'
I have came up with the following regex:
(?:RegExp)\((.*)\)
It works fine for most examples, but fails for some cases (e.g. minified, 1 line JavaScripts, regexs including parentheses):
RegExp("myregex") - capturing group 1: "myregex"
Regexp("something"); myfunction("something") - capturing group 1: "something"); myfunction("something"
RegExp("my(regex)") - capturing group 1: "my(regex
This is clearly due to finding a matching closing parenthesis. Is there a workaround for this?