I need some help for creating the regex expressions for a function list for vbscript.
There are two kinds of definitions for functions and subs in vbscript:
In the function list I want to see only the names of the functions and Subs (in this example test1 and test2) without the prefixes function or Sub.
How do I do that?
I found the solution (may be it will help other People):
mainExpr="^[\t ]*[fFsS](unction|ub)[\t ]+\w+"
Thanks for sharing your results with the N++ community :-)
I just want to add two points :
The regex, used in your mainExpr item, would also match lines beginning with one of the four words Fub, fub, Sunction or sunction !!
Of course, misspelling the word Function or Sub, in such that way, is almost impossible. But, in theory, this regex should be strictly re-written :
mainExpr="^[\t ]*([fF]unction|[sS]ub)[\t ]+\w+"
The regex, used in your expr item, can be simplified :
A first idea, that comes to mind, is to use ONLY ONE lookbehind, with the alternative, inside round brackets, as below :
But this regex in INVALID, because the two terms of the alternative MUST have the same length, when used inside a lookbehind. Obviously, it's NOT the case :
[fF]unction is a 8 characters string and [Ss]ub is a 3 characters string !
But, luckily, there's a special form \K, which can REPLACE lookbehind, with non-fixed length :
This regex try, first, to match one of the four words Function, function, Sub, or sub
Then, the \K form FORGET any previous search matched. So, the FINAL search is ONLY the regex [\t ]+\w+
Just note that, on the contrary, you can use lookahead with non-fixed length, as, for example, the regex ABC(?=(DE|WXYZ)), which would match the string ABC, ONLY if it's FOLLOWED with the string DE or the string WXYZ !
You will find good documentation, about the new PERL Common Regular Expressions (PCRE), used by N++, since the 6.0 version, at the TWO addresses below :
The FIRST link concerns the syntax of regular expressions in SEARCH
The SECOND link concerns the syntax of regular expressions in REPLACEMENT
Very good comment from an expert!
I didn't know the option \k, so thanks for this tip and for the links.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.