Solved

RegEx Question

Posted on 2006-07-20
1
153 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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

16 Experts available now in Live!

Get 1:1 Help Now