匹配脚本中的 php 类并为找到的每个类创建单独的文件
我的问题是使用正则表达式来匹配类并跳过引号内的内容。我也不知道如何跳过用于关闭类内方法的 '},因此引擎认为它已到达类的末尾。
后来我想为每个匹配的类创建单独的文件。例如:
{$classname}.php >> content
这是必要的,因为我有一种糟糕的做法,开始在一个文件中编写许多类,然后只有当我得到一些“内容”时,我才决定将它们放在单独的文件中,这当然太无聊并且花费我的很多时间。你能帮我解决这个问题吗?特别是正则表达式,但其余的请随意;)
My problem is with the regex to match classes and skip content that is within quotes. I also don't know how to skip the '}'s that are used to close methods inside the class, so the engine thinks that it is reaching the end of the class.
Later then I want to create separate files for each class matched. For example:
{$classname}.php >> content
This is needed because I have the terrible practice of start coding many classes in one file and then only when I've got something "meaty" then I decide to put them in separate files, which of course is too boring and spend a lot of my time. Could you help me with this please? Specially the regex, but feel free do the rest ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正则表达式不是为解析编程语言(特别是嵌套)而设计的。如果您需要移动代码方面的帮助,请获取具有重构工具的 IDE。
Regex is not designed to parse programming languages (specifically nesting). Get an IDE that has refactoring tools if you want help moving code around.