I need to extract in Notepad++ from a package body file the object name (function, procedures, etc) and the description from the object.
I know that is possible by regex but sometimes the comments are compound for more than 3 lines.
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;
And in this case, I need only to replace all in document and get something like:
/* *********************************************
* 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
Or (best scenario) this:
FUNCTION f1 Search for a data in table1
FUNCTION f2 Search for a data in table2
答案 0 :(得分:1)
(?:\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
屏幕截图:
答案 1 :(得分:0)
To do this in Notepad++ I would:
^([ \t\*]+)(FUNCTION|PROCEDURE)([ \t]+)([A-Z_0-9]+)
. Choose on the Mark tab and click Mark all.^([ \t\*]+)Description: (.+)
. Again click Mark all.This will give you the basis for best scenario. It's a simple matter to tidy the lines from there using regex replace.
Notes:
* Function f2
. You close the capitalisation but at least it's in the right order. Otherwise you'd need to switch the procedure name and description for every line.^([ \t]*)(FUNCTION|PROCEDURE)([ \t]+)([A-Z_0-9]+)
and re-order the descriptions