Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Software Development
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry router security slow software sound toshiba trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
Yet another regular expression problem

Reply  
Thread Tools
gdi1942's Avatar
Member with 217 posts.
 
Join Date: Nov 2006
Experience: Advanced
23-Oct-2009, 12:27 PM #1
Yet another regular expression problem
Hi folks, i have a string that contains a collection of visual basic methods, i'm trying to write a regular expression statement that can catch methods that look like this.

Code:
		Public Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
			(A Bunch of code lines here)
		End Sub
What I've got so far for a regular expression is

Code:
"Public\\sSub\\s(.*)_(.*)\\sHandles\\s(.*)\\.(.*)\\s?\\n(.*\\n)\\s*End\\sSub"
The trouble is it returns no matches and I'm not sure why. Seems regular expressions are meant to function on single line strings. I've tried removing the End Sub portion of the the expression and that works, giving me just the header and it's match groups. I'm coding this in c#. Thanks for any help you can provide.
JimmySeal's Avatar
Computer Specs
Member with 289 posts.
 
Join Date: Sep 2007
Experience: Getting there
24-Oct-2009, 06:22 AM #2
I just ran that expression through Expresso and it seemed to match that string alright. Regular expressions can certainly be used to match multi-line strings. Try replacing your \ns with [\n\r]+.

I'd also suggest using @ at the beginning of your string (i.e. before the opening quote mark) so that you don't have to use double backslashes. It makes the strings quite a bit more readable.
gdi1942's Avatar
Member with 217 posts.
 
Join Date: Nov 2006
Experience: Advanced
24-Oct-2009, 05:22 PM #3
A co-worker of mine helped me resolve the problem. The trick was to use *? on the ,*\\n part wihch means to match as little as possible. The statement now looks like

Public\\sSub\\s(.*)_(.*)\\sHandles\\s(.*)\\.(.*)\\s?\\n((.*\\n)*?)\\s*End\\ sSub"
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:58 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.