Pattern Matching in VB.NET 2003

KrAcKeD

Member
Joined
Jul 14, 2006
Messages
9
Programming Experience
5-10
Hi,

I've been trying to get a pattern to work, I'm almost at it, but still not yet.
Basically what I want the pattern to do is find from all function header to the "End function" and I will later change the pattern when this one work to make it find only the functions for which i will need to change some stuff
Basically, declaring datasets, datatables, and other disposable items withough disposing them in the "Finally" of the "Try"

I have one that works, but doesn't quite do what i want it to do, I'll explain the problem after.
^:b*(Public|Private) (Function|Procedure)(.*\n)*:b*End Function|Procedure

This one above does work, but in a file where i have 20 functions or procedures, it matches the first "(Public|Private):b(Function|Procedure)" to the last "End (Function|Procedure)".

What I want it to do is match only ONE function or procedure from its header to it's respective "End"

I tried the negative lookaround on the dot :
^:b*(Public|Private) (Function|Procedure)(.(?!End (Function|Procedure))*\n)*.*End (Function|Procedure)

It just doesn't match anything, I've tried about 25 different way to write the pattern but I just couldn't find one that matches what I wanted.

It would be easy if I could use the Lazy operator on my star, but unfortunately, i'm using the "Pattern Matching" of VB.NET 2003 ( When you press ctrl+f and check "Use regular expression" )

Can anyone help me find a pattern matching for this ?
 
I wrote this myself, not using any tools, just my head

This is what I think the pattern does, and I dont understand where I am wrong, please point it out

^:b*(Public|Private) (Function|Procedure)(.(?!End (Function|Procedure))*\n)*.*End (Function|Procedure)

Matches :

^ : Beginning of line
:b* : Any number of spaces or tabs
(Public|Private) : Exactly "Public" OR "Private"
: A space
(Function|Procedure) : Exactly "Function" OR "Procedure"
(.(?!End (Function|Procedure))*\n)* : Any Amount of the pattern inside the ()
.(?!End (Function|Procedure))* : Any amount of any character that is not followed by Exactly "End " followed by Exactly "Function" OR "Procedure"
\n : A line break
.* : Any amount of any character
End (Function|Procedure) : Exactly "End " followed by Exactly "Function" OR "Procedure"
 
Back
Top