Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

Using Regex to find non-commented string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tawright915 - 03 Oct 2007 17:33 GMT
Ok so here is my regex (--.*\n|/\*(.|\n)*?\*/).  It finds all comments
just fine.  However I want it to return to me all strings that are not
commented out.  Is there a way to exclude the comments and only show
the non-commented strings

Here is an example of the data that I am working with
/*
select * from db2
*/

/* select * from db3 */

-- select * from db4

select * from db5

I want to only see the select statement for db5.  This is for a query
program that I wrote in C# and I need to find out where the comments
query commands are and those that are not commneted.

Thanks
Tom
Mark Peters - 03 Oct 2007 17:44 GMT
> Ok so here is my regex (--.*\n|/\*(.|\n)*?\*/).  It finds all comments
> just fine.  However I want it to return to me all strings that are not
> commented out.  Is there a way to exclude the comments and only show
> the non-commented strings

You could use Regex.Replace() to replace the comments with an empty
string.  That should leave you with the non-commented strings.
(Replace will return a new string, of course)
Jesse Houwing - 04 Oct 2007 00:04 GMT
Hello Mark,

>> Ok so here is my regex (--.*\n|/\*(.|\n)*?\*/).  It finds all
>> comments just fine.  However I want it to return to me all strings
[quoted text clipped - 4 lines]
> string.  That should leave you with the non-commented strings.
> (Replace will return a new string, of course)

That or use Regex.Split to get all the parts that are not commented.

It should return an array with the uncommented parts.

You can also use the different matches and use the start and end positions
of them to deduce the non-commented parts.

--
Jesse Houwing
jesse.houwing at sogeti.nl

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.