正则表达式匹配相同或父类函数的函数调用

I have below regex to match all function statements in any php file. But it matches the function definitions as well.

[a-zA-Z]+\([^\)]*\)(\.[^\)]*\))?

Now I need to modify this regex to match only function calls(not definition/declaration) that are called like $this->funcName( or $anyObject->funcName( or self::funcName( or parent::funcName(.

I tried modifying the regex, but it breaks when I use $ in it. Can someone help out ?

A sufficient regex would be:

(?:\$[A-Za-z_]\w*->|self::|parent::)[A-Za-z_]\w*\([^)]*\)

Regex101 Demo

This also asserts that the variables and functions follow correct naming syntax:

  • The first character of a variable is a $.
  • The first character of a variable/function name is a letter or underscore.
  • All remaining characters of a variable/function name are letters, numbers, and underscores.