[英]Oracle Scripts parsing using regex
I am trying to parse the oracle scripts. 我正在尝试解析oracle脚本。 The purpose is to extract the number of functions, procedures, Loops, Exceptions etc. What is the most suitable way to accomplish this?
目的是提取函数,过程,循环,异常等的数量。最合适的方法是什么? I am currently doing this with regex.
我目前正在使用正则表达式执行此操作。 But it seems that it is not covering all the scenarios.
但这似乎并没有涵盖所有情况。 I need some alternative for this.
我需要一些替代方法。
I have created a following regex expression to find out the Packages, functions, procedures, loops, exceptions, metadata definitions, and anonymous blocks. 我创建了以下正则表达式表达式,以查找包,函数,过程,循环,异常,元数据定义和匿名块。
"create\\s+(or\\s+replace\\s+)?(package)\\s+(body\\s+)?([\\w\\.]+)" +//1-4
"|(\\bcreate\\s+)?(\\bor\\s+)?(\\breplace\\s+)?(\\bfunction|\\bprocedure)\\s+(\\w+)" +//5-9
"|(\\bexception)\\s" +//10
"|(\\bcursor)\\s*(\\w+)"+//11-12
"|(\\bloop)\\s"+//13
"|(\\w+)\\s*([\\w\\.]+)\\s*%(ROW)?(TYPE);"+//14-17
"|(\\bdeclare)\\s"//18
The technique is to eliminate the comments, and string literals and then apply the regex. 该技术是消除注释和字符串文字,然后应用正则表达式。 It is working fine for me.
对我来说很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.