【问题标题】:Get function and description comment in a pl/sql body package file在 pl/sql 正文包文件中获取函数和描述注释
【发布时间】:2019-04-08 13:36:29
【问题描述】:

我需要在 Notepad++ 中从包体文件中提取对象名称(函数、过程等)和对象描述。

我知道这可以通过正则表达式实现,但有时 cmets 复合超过 3 行。

CREATE OR REPLACE PACKAGE BODY pac_example AS

/* *********************************************
*  Function f1
*  Description: Search for a data in table1
*  (another comments)
*  ******************************************* */
FUNCTION f1 RETURN NUMBER IS
BEGIN
SELECT * FROM table1;
RETURN 1;
END f1;



/* *********************************************
*  Function f2
*  Description: Search for a data in table2
*  (another comments)
*  (another comments)
*  (another comments)
*  ******************************************* */
FUNCTION f2 RETURN NUMBER IS
BEGIN
  SELECT * FROM table2;
RETURN 1;
END f2;

END pac_example;

在这种情况下,我只需要替换文档中的所有内容并获得如下内容:

/* *********************************************
*  Function f1
*  Description: Search for a data in table1
*  (another comments)
*  ******************************************* */
FUNCTION f1 RETURN NUMBER IS
/* *********************************************
*  Function f2
*  Description: Search for a data in table2
*  (another comments)
*  (another comments)
*  (another comments)
*  ******************************************* */
FUNCTION f2 RETURN NUMBER IS

或者(最好的情况)这个:

FUNCTION f1 Search for a data in table1
FUNCTION f2 Search for a data in table2

【问题讨论】:

  • 所以您不需要过程签名的详细信息(参数、返回类型)?

标签: regex plsql notepad++


【解决方案1】:
  • Ctrl+H
  • 查找内容:(?:\A.*?|\G)\*\h+((?:Function|Procedure)\h*\w+).*?Description:\h*([^\r\n]+\R)(?:(?!\*\h+(?:Function|Procedure)).)+
  • 替换为:$1 $2
  • 取消选中匹配大小写
  • 检查环绕
  • 检查正则表达式
  • 检查. matches newline
  • 全部替换

说明:

(?:                         # non capture group
    \A                      # beginning of file
    .*?                     # 0 or more any character
  |                         # OR
    \G                      # restart from last match position
)                           # end group
\*                          # an asterisk
\h+                         # 1 or more horizontal spaces
(                           # start group 1
    (?:Function|Procedure)  # literally Function OR Procedure
    \h+                     # 1 or more horizontal spaces
    \w+                     # 1 or more word character
)                           # end group 1
.*?                         # 1 or more any character, not greedy
Description:\h*             # literally Description followed by horizontal spaces
(                           # start group 2
    [^\r\n]+                # 1 or more any character not linebreak
    \R                      # any kind of linebreak
)                           # end group 2
(?:                         # Tempered greedy token
    (?!                     # negative lookahead
        \*                  # an asterisk
        \h+                 # 1 or more horizontal spaces
        (?:Function|Procedure)  # literally Function OR Procedure
    )                       # end lookahead
    .                       # any character
)+                          # end group, appears 1 or more times

替换:

$1          # content of group 1, function or procedure
$2          # content of group 2, description

屏幕截图:

【讨论】:

    【解决方案2】:

    要在 Notepad++ 中执行此操作,我会:

    1. ^([ \t\*]+)(FUNCTION|PROCEDURE)([ \t]+)([A-Z_0-9]+) 的正则表达式。在标记选项卡上选择,然后单击全部标记
    2. 现在搜索^([ \t\*]+)Description: (.+)。再次点击全部标记
    3. 菜单 搜索 > 书签 > 复制书签行
    4. 粘贴到新文档中。

    这将为您提供最佳方案的基础。使用正则表达式替换从那里整理行是一件简单的事情。

    注意事项:

    • 第一步从 cmets 中选择过程名称,即* Function f2。您关闭了大写,但至少它的顺序正确。否则,您需要为每一行切换过程名称和描述。
    • 如果您需要签名详细信息(参数等),这并不好。然后您需要搜索^([ \t]*)(FUNCTION|PROCEDURE)([ \t]+)([A-Z_0-9]+) 并重新排序描述
    • 我已经包含了制表符和空格模式,因为不清楚您的源代码是如何缩进的

    【讨论】:

      猜你喜欢
      • 2020-12-31
      • 1970-01-01
      • 2013-07-15
      • 2021-07-27
      • 1970-01-01
      • 2021-06-16
      • 1970-01-01
      • 1970-01-01
      • 2020-06-24
      相关资源
      最近更新 更多