duanchuonong5370 2011-08-16 15:52
浏览 45
已采纳

正则表达式查找父::

I want to find all occurrences of parent::, the called function and the parameter

For example:

parent::test( new ReflectionClass($this) );

But the following regular expression doesn't match the outer brackets - only the inner ones:

parent::(.*)\((.*)\);
Array /* output */
(
    [0] => parent::test( new ReflectionClass($this) );
    [1] => test( new ReflectionClass
    [2] => $this) 
)

How do I have to modify the pattern?

That is for a PHP script, so I can use some other string functions, too.

  • 写回答

4条回答 默认 最新

  • dongrong5189 2011-08-16 15:56
    关注

    What you are trying to do is generally not possible with regular expressions. To do what you want, you have to be able to count things, which is something regular expressions can't do.

    Making the matching greedy will eventually lead to matching too much, especially when you are supporting multiple line input.

    To replace every occurence of parent:: you probably don't have to match the method call exactly, maybe it is enough to match something like this:

    parent::(.*);
    

    Then you can replace the parent:: with something else and use the first matching group to put whatever was in the document at this position.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料