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
> 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