Solved

RegEx Question

Posted on 2006-07-20
1
154 Views
Last Modified: 2010-04-30
I am trying to write a program the recognizes VB lines such as Public Sub.....() Private Function....() etc..

I do NOT want Private|Public Declare statements. Only subs and functions.

The regular expression I am using is:

.Pattern = "[Private|Public Function|Sub].*\)"

That is, of course, picking up the Declare statements. How do I write one that says "Private or Public AND one space AND Function or sub, followed by any number of anything, and ending in a closed parenthesis"?
0
Comment
Question by:DrDamnit
1 Comment
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 500 total points
ID: 17152909
Hi, the following regex should do what your after:

^(Private|Public)\s{1}(Function|Sub).+\)$

Explanation: string must start with either Private or Public followed by one empty space then either Function or Sub and finally one or more of any character then finally finishing with a closing bracket.. I don't know if you want to cater for this situation but a function signature ends with the return type ... e.g.

Public Function ProcessSomething(ByVal Data As String) As Boolean

Your current regex says that the last character should be a closing bracket... if you want to match a full function signature then you could use the following regex:

^(Private|Public)\s{1}(Function|Sub).+(As\s.+|\))$
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now