473,394 Members | 1,845 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,394 software developers and data experts.

Using Regex to find non-commented string

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

Oct 3 '07 #1
2 1788
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)

Oct 3 '07 #2
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
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)

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
Oct 3 '07 #3

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

Similar topics

5
by: lawrence | last post by:
When users enter urls or other long strings it can destroy the formatting of a page. A long url, posted in a comment, can cause page distortions that make the page unreadable, till the website...
26
by: codymanix | last post by:
Last night I had several thought about RAII and want to discuss a bit. Why doesn't CSharp support destructors in structs? Wouldn't that make RAII possible like in C++? When the struct goes out of...
11
by: rajarao | last post by:
hi I want to remove the content embedded in <script> and </script> tags submitted via text box. My java script should remove the content embedded between <script> and </script> tag. my current...
8
by: Bibe | last post by:
I've been trying to get this going for awhile now, and need help. I've done a regex object, and when I use IsMatch, it's behavior is quite weird. I am trying to use Regex to make sure that a...
6
by: Mike | last post by:
I need some help. This regular expression strips out html tags "<>" /*Strips the HTML tags from strHTML */ Regex objStripHTML = new Regex("<(.|\n)+?>"); How would I construct a Regular...
1
by: | last post by:
Hi, I have a Regular Expression that will match the format a user provides in a textbox. Ex. Brown,Joe in the textbox I would like the expression to have both whitespace and...
2
by: UJ | last post by:
What's the general feeling on using the using keyword versus spelling the type out completely. For instance, do most people put a using in so they can just say MyNewType or do people not use...
3
by: WLT | last post by:
I need to filter out non-legal characters from potential (user-entered) file names. Certainly this must exist already. Also...I remember there was a large cache of regex strings online...
4
by: Julius Fuchs | last post by:
Hi, I have a string like "bla<cut>blubb<cut>bla<cut>blubb" and want to replace the substring from the first occurrence of <cut> to the second with "TEST" in order to get "blaTESTbla<cut>blubb"....
6
by: deepak_kamath_n | last post by:
Hello, I am relatively new to the world of regex and require some help in forming a regular expression to achieve the following: I have an input stream similar to: Slot: slot1 Description:...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...

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.