473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Regular Expression to Capture VB Declarations in Visual Studios Find/Replace

I'm trying to use Visual Studio's Find/Replace to match VB declarations. This RegEx
works fine in Regulator:
^\s*(Public|Friend|Protected|Private)*\s*(Shared|O verrides)*\s*(Sub|Function|Property
)+

But when I try it in Visual Studio's find (with regular expressions turned on) it
doesn't work. Are there any known problems with VS find or is there something wrong
with the above expression? I'm new to them, so the second question could easily be
the case.

Also, Ive seen example programs that use RegEx to parse code to format as html, but I
can't remember where it was. Anyone remember this?

Thanks in Advance - JackRazz
Nov 16 '05 #1
4 2049
The regex engine in the Find... dialog isn't the one provided by the .net
framework. Click the 'Help' button to get a list of regex expressions valid
in the find/replace dialogs.
I think the main difference for you regex is that spaces are matched by ":b"
in the find dialog.

"JackRazz" <Ja******@NotValid.com> wrote in
news:u0**************@TK2MSFTNGP12.phx.gbl...
I'm trying to use Visual Studio's Find/Replace to match VB declarations. This RegEx works fine in Regulator:
^\s*(Public|Friend|Protected|Private)*\s*(Shared|O verrides)*\s*(Sub|Function
|Property )+


You know this matches "FriendFriendFriendOverridesSharedSubSubSub", too?
Maybe try something like
:b*(|Public|Friend|Protected|Private):b+(|Shared|O verrides):b+(Sub|Function|
Property)

Niki
Nov 16 '05 #2
Niki,
That was it! Thanks. I think I'm finally getting these regular expressions. This
is my new expression:
(Public|Friend|Protected|Private):Zs*(Shared|Overr ides|.):Zs*(Sub|Function|Property):
Zs+

One question, I'm having problems with the middle section for the optional Shared or
Overides keyword. It seems to me that this should work, but doesn't:
(Shared|Overrides):Zs*

If I add the last '|.', it works
(Shared|Overrides|.):Zs*

Any ideas why I need the '|.' as the * at the end of the middle section should make
it optional ie. 0 is ok

Thanks - JackRazz

"Niki Estner" <ni*********@cube.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
| The regex engine in the Find... dialog isn't the one provided by the .net
| framework. Click the 'Help' button to get a list of regex expressions valid
| in the find/replace dialogs.
| I think the main difference for you regex is that spaces are matched by ":b"
| in the find dialog.
|
| "JackRazz" <Ja******@NotValid.com> wrote in
| news:u0**************@TK2MSFTNGP12.phx.gbl...
| > I'm trying to use Visual Studio's Find/Replace to match VB declarations.
| This RegEx
| > works fine in Regulator:
| >
| >
| >
| ^\s*(Public|Friend|Protected|Private)*\s*(Shared|O verrides)*\s*(Sub|Function
| |Property
| > )+
|
| You know this matches "FriendFriendFriendOverridesSharedSubSubSub", too?
| Maybe try something like
| :b*(|Public|Friend|Protected|Private):b+(|Shared|O verrides):b+(Sub|Function|
| Property)
|
| Niki
|
|
Nov 16 '05 #3
"JackRazz" <Ja******@NotValid.com> wrote in
news:e5**************@TK2MSFTNGP10.phx.gbl...
Niki,
That was it! Thanks. I think I'm finally getting these regular expressions. This is my new expression:
(Public|Friend|Protected|Private):Zs*(Shared|Overr ides|.):Zs*(Sub|Function|P
roperty): Zs+

One question, I'm having problems with the middle section for the optional Shared or Overides keyword. It seems to me that this should work, but doesn't:
(Shared|Overrides):Zs*
The '*' quantifier only applies to one character. You can make it apply to a
larger pattern by using baces:
((Shared|Overrides):Zs*)*
Read: "Shared or Overrides, followed by any number of spaces, the whole
repeated any number of times"
If I add the last '|.', it works
(Shared|Overrides|.):Zs*

Any ideas why I need the '|.' as the * at the end of the middle section should make it optional ie. 0 is ok


See above.
BTW: You don't need "|.", but only "|" (i.e. (a|b|c|) makes the whole thing
optional).

Niki
Nov 16 '05 #4
Thanks Niki,
I thought it applied to the whole thing. Appreciate your help.

JackRazz

| The '*' quantifier only applies to one character. You can make it apply to a
| larger pattern by using baces:
| ((Shared|Overrides):Zs*)*
| Read: "Shared or Overrides, followed by any number of spaces, the whole
| repeated any number of times"
|
| > If I add the last '|.', it works
| > (Shared|Overrides|.):Zs*
| >
| > Any ideas why I need the '|.' as the * at the end of the middle section
| should make
| > it optional ie. 0 is ok
|
| See above.
| BTW: You don't need "|.", but only "|" (i.e. (a|b|c|) makes the whole thing
| optional).
|
| Niki
|
|
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
5
by: Bradley Plett | last post by:
I'm hopeless at regular expressions (I just don't use them often enough to gain/maintain knowledge), but I need one now and am looking for help. I need to parse through a document to find a URL,...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
11
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However,...
4
by: JackRazz | last post by:
I'm trying to use Visual Studio's Find/Replace to match VB declarations. This RegEx works fine in Regulator: ...
4
by: JackRazz | last post by:
Could someone give me a very simple regular expression for Visual Studio's search/replace using backreferences saving portions of the match as \1 or $1 or whatever. I want to use something I can...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
4
by: JJ | last post by:
I can get a set of matches of URL's by using a match expression that has a named capture group in it, i.e.: Regex reg_linkTags = new Regex("(?:.....long resular...
3
by: rupinderbatra | last post by:
Hello everyone, I am using a regular expression to parse a text string into various parts -- for ex: string "How do you do" will be changed to array with all the words and white spaces. I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.