使用正则表达式搜索函数中的内容
我如何使用正则表达式搜索包含全局变量使用的函数,而无需先运行“global $var”?
文件如下所示:
class TestClass
{
function correctFunc()
{
global $var;
$name = $var->name;
}
function invalidFuncIWantToFind()
{
$age = $var->user->age;
}
}
我想查找所有 invalidFuncIWantToFind 的函数名称。在工作中,这确实会加快我们的工作速度,但我不知道该怎么做。
How would I with regular expression search for functions which contains the use of a global variable without running "global $var" first?
The files looks like this:
class TestClass
{
function correctFunc()
{
global $var;
$name = $var->name;
}
function invalidFuncIWantToFind()
{
$age = $var->user->age;
}
}
I want to find the function names of all the invalidFuncIWantToFind. At work this would have really speeded up our work but I didn't get how to do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的正则表达式实现,您也许可以为此使用回顾模式。 http://www.regular-expressions.info/lookaround.html 声称例如.NET Framework 实现可以做到这一点。 (问题是,lookbehind 可以包含可变数量的字母......这似乎会引起麻烦)。
由于我手头没有 Visual Studio,因此我无法为您构建正则表达式,抱歉。
Depending on your Regex implementation, you might be able to use a lookbehind pattern for this. http://www.regular-expressions.info/lookaround.html claims that e.g. the .NET Framework implementation can do this. (Problematic is, that the lookbehind can contain a variable number of letters... this seems to cause trouble).
Since I do not have a Visual Studio at hand here, I cannot build a Regex for you, though, sorry.