Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex:获取分配给属性的JS函数的内容_Regex - Fatal编程技术网

Regex:获取分配给属性的JS函数的内容

Regex:获取分配给属性的JS函数的内容,regex,Regex,我只需要获取此函数的内容作为字符串: (lib.foobar = function(mode, startPosition, loop) { // contents to grab }).prototype = getMCSymbolPrototype(lib.foobar, new cjs.Rectangle(0, 0, 59.7, 59.4), null); 我做到了这一点,但在开始大括号之前无法排除所有内容:foobar=function(mode,startPosition,l

我只需要获取此函数的内容作为字符串:

(lib.foobar = function(mode, startPosition, loop) {
    // contents to grab
}).prototype = getMCSymbolPrototype(lib.foobar, new cjs.Rectangle(0, 0, 59.7, 59.4), null);
我做到了这一点,但在开始大括号之前无法排除所有内容:
foobar=function(mode,startPosition,loop){

(?={)。*(?=})

(?=foobar.+{.+(?=})

试试正则表达式:

(?:(?!foobar.*\n)\n)(?:.*\n)*(?=})

请参阅

一般来说,不应使用regex解析编程语言。
(?@chrisz,它似乎工作得很好,因为.*是贪婪的。@chrisz你说得对,但我们在这里没有选择-除非我们得到了从Adobe Animate CC导出的生成EaselJS动画的代码。@Matt.G JS不支持lookbehinds。只有最新版本的Google Chrome支持它。有趣的解决方案。谢谢!