dragon7713 2016-08-31 06:20
浏览 91
已采纳

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

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 ?

  • 写回答

1条回答 默认 最新

  • dougaimian1143 2016-08-31 06:40
    关注

    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.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器