Hello everyone!
I'm trying to write a regular expression to capture VB6 function
definitions and I'm abit stuck. The rules are:
Function header:
* Must contain the words SUB or FUNCTION
* May contain the words PUBLIC or PRIVATE
* May NOT contain the word DECLARE
* Ends at the first newline that is not preceded by an underscore (_)
followed by a space.
Function footer
* Must contain the words END FUNCTION or END SUB only
Function exit:
* Must contain the words EXIT FUNCTION or EXIT SUB only
The idea is that I want to insert some logging code after each
function header and some logging code before each exit or end. So what
I need is a regex that would capture whole functions with groups for:
* Whole function header
* Function name
* Function parameter list
So far I've come up with
(?:^\s*(?:public|private){0,1}\s(?:sub|function)\s ) (?<FunctionName>[\w
\d]+) (?<FunctionArgs>(?:\s*.*_\s$)*(?:\s*.*$) | (?:.*$)) # FUNCTION
HEADER
and
(^\s*(?:end|exit)\s(?:sub|function)).*$ # FUNCTION FOOTER
but I don't really know how to combine them to get the complete
function back with the exits and ends tagged properly.
Could someone plese help me out with some tips?
Regards,