正则表达式匹配函数名称但不匹配源代码中的声明

Regex that match functions name but not declarations in source code

我试图在源代码中而不是在函数声明中查找函数名称。假设我们有以下源代码:

function foo()
{
 if ( ! foo5() )
  foo3(bar("string"), foo2());
 else
  foo3(bar("string"));
}

function foo4()
{
 if (!foo5())
  bar2(bar("string"), foo2());
 else
  bar2(bar("string"));
}

我想提取 foo5,foo3,bar,foo2,bar2 不是 foofoo4

我尝试了 following regex 但没有成功

(?<!function )(\w+)\(

所有有左括号但不以 function

开头的单词

试试这个正则表达式:

(?<!function )(\b\w+)\(

据我所知,它适用于您的示例。