By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,028 Members | 1,869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,028 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.