Solved

RegEx Question

Posted on 2006-07-20
1
157 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

756 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