解析函数定义 [英] parse for a function definition

查看:95
本文介绍了解析函数定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在shell脚本中搜索特定的函数,并将其替换为我可以使用sed inplace editor的修改过的函数。但我无法正确解析该功能。我可以使用正则表达式来搜索形式的函数

函数()

{

之间没有其他大括号

}

I need to search for a particular function in a shell script and replace it with the modified function for which I can use sed inplace editor. But I am not able to correctly parse for the function. Can I have a regular expression to search for the function which is of the form
function()
{
no other braces in between
}

推荐答案

如果没有大括号让它变得容易多了。

试试 function [^ {] * {[^}] *}
If there''s no braces that makes it a lot easier.
Try function[^{]*{[^}]*}


很抱歉,但它确实在函数内部有一些大括号..所以我不知道如何解析直到函数结束
I am sorry but it does have some braces inside the function.. so I dont know how to parse until the end of function


试试@Rabbit放在上面的内容?您可以使用左括号搜索功能的开头直到结束括号。你试过他发布的内容了吗?它有效吗?
Try what @Rabbit put in above? You search from the beginning of the function with the opening bracket until the closing bracket. Did you try what he posted? Did it work?


这篇关于解析函数定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆