RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^(Function|Sub)(\s+[\w]+)\([^\(\)]*\)
Description
Updated, changed [\w]* to [\w]+ because pattern should not match Sub (), there would be no function name which would be incorrect. Will extract function declarations from ASP or also VB I assume. Will even capture declarations that break across new lines or ones that use the underscore(line continuation character) in Microsoft's VB, VBA, ASP, etc. Had to put this together to document some code on a project and didn't see anything like it on the web. I hope it helps out anyone else who has to re-engineer ASP or VB code.
Matches
Function MyFunc(Arg1, Arg2, Arg3, Arg4)
Non-Matches
'This is a comment for MyFunc(Arg1,Arg2,Arg3) and this regexp wouldn't work.
Author Rating: Not yet rated. James Fal
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Much better
Name: Darren Neimke
Date: 11/23/2003 4:23:44 PM
Comment:
Looks great! Sorry about my error in mentioning the parenthesis thing; I guess that I've become so accustomed to allowing Visual Studio to write my code that I've forgotten what it really should be :-) BTW... if you are interested in regex's you might like to keep an eye on my blog about them: http://regexblogs.com/DNeimke Or, you might even like to get your own: http://regexblogs.com/dneimke/posts/176.aspx Cheers, - Darren


Title: Fixed
Name: James
Date: 11/23/2003 11:19:08 AM
Comment:
I fixed the regexp. I also double checked my VB6 IDE and sure enough it puts parens after a Sub if you don't put them there yourself. Gotta love that helpful code completion. I appreciate the help, looks like you are well past me in the RegExp world.


Title: Thanks!
Name: James
Date: 11/23/2003 10:59:37 AM
Comment:
Thanks for the tip. I needed a [\w]+ there don't I? The Sub Foo example is wrong though, it shouldn't match that. VB based languages require the declaration for a Sub to at least be: Sub MySub() ...code... End Sub Now if I were trying to match a Call statement, like Call Foo, then the parens would be optional.


Title: Not quite
Name: Darren Neimke
Date: 11/23/2003 4:49:59 AM
Comment:
The following part allows no name: [\w]* therefore your pattern would match: Sub () which is incorrect because the method name is missing and, would fail against: Sub Foo which should succeed because parenthesis are optional for a Sub.


Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials