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

Regular Expression question

Hi,

I am stuck trying to come up with a regular expression for the following
pattern:
A string that contains "/*" but that does not contain */ within it.
Basically I am searching for C-style multiline comments and would much
rather use Regex than strings.

Here is what I have, but it does not seem to work.
Match match = Regex.Match(textLine, @"\s*(/[*])(?<comment>(?![*]/).*)$");

There is something wrong with the fact that the match should succeed only if
the string "*/" is not found.

Any input would be greatly appreciated!

Thanks,

Natalia
Nov 16 '05 #1
8 2102
Hi

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconspecifyingfullyqualifiedtypenames.ht

You can show in this msdn document

Maybe you need just "/"

Show that a documen

Thanks

_________________________
Have a Good Day
_________________________
Mail :le*****@korea.co
Mail2:Jh***********@oecd.or
MSN :le*****@Korea.co
Tel. :33-1-7142-640
_________________________
http://leehack.sarang.net
Nov 16 '05 #2
Maybe not what you want, but it may be better to test that is IS a match on the regex "/\*[.\s\S]"
but DOESN'T match "/\*[.\s\S]/\*"
Nov 16 '05 #3
Woul
@"/\*(?![\s\S.]*\*/)

Do what you want

Nov 16 '05 #4


Hi sevenfifteen,

Thanks so much for replying to my message. Your suggestion worked
indeed. Thanks!

I am stuck here on another problem, trying to come up with a regular
expression for the following case:
a. if a substring "/*" is detected, there is no "*/" that would follow;
b. if a substring "/*" is detected, there is neither "//" nor "/" that
preceeds it.

Part a is working fine, but when I add part b to it, things become
broken once again.

I have tried a few reg. ex.'s but nothing seems to work.

Here is what I have tried so far:
@"\s*(?!//?.*)(/[*])(?!.*[*]/)(?<comment>.*)"
@"\s*(?!.*//?)(/[*])(?!.*[*]/)(?<comment>.*)"
@"\s*(?<!//?.*)(?<=/[*])(?!.*[*]/)(?<comment>.*)"

Not sure where my logic is wrong.

Any help would be greatly appreciated!

Thanks,
Natalia

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5
Trying to match comments in /* */ pairs appears to be what you are doing.
Based on the semantics of something like c# it requires more logic than what
you are using.

"(?ms)^(?!.*//.*).*/\\*(?<comments>.*)\\*/"

The above is a C# escaped string that will match comment structures
not preceded by line comments "//".
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Natalia DeBow" <na***********@unisys.com> wrote in message
news:e9**************@TK2MSFTNGP11.phx.gbl...


Hi sevenfifteen,

Thanks so much for replying to my message. Your suggestion worked
indeed. Thanks!

I am stuck here on another problem, trying to come up with a regular
expression for the following case:
a. if a substring "/*" is detected, there is no "*/" that would follow;
b. if a substring "/*" is detected, there is neither "//" nor "/" that
preceeds it.

Part a is working fine, but when I add part b to it, things become
broken once again.

I have tried a few reg. ex.'s but nothing seems to work.

Here is what I have tried so far:
@"\s*(?!//?.*)(/[*])(?!.*[*]/)(?<comment>.*)"
@"\s*(?!.*//?)(/[*])(?!.*[*]/)(?<comment>.*)"
@"\s*(?<!//?.*)(?<=/[*])(?!.*[*]/)(?<comment>.*)"

Not sure where my logic is wrong.

Any help would be greatly appreciated!

Thanks,
Natalia

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #6
"(?ms)^.*?(?<!//[^\\n]*)/\\*(?<comments>.*)\\*/"

The above is a little better from what I can tell. You may
also need to make (?<comments>.*?), so that you don't
eat past the end of a comment.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Justin Rogers" <Ju****@games4dotnet.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Trying to match comments in /* */ pairs appears to be what you are doing.
Based on the semantics of something like c# it requires more logic than what
you are using.

"(?ms)^(?!.*//.*).*/\\*(?<comments>.*)\\*/"

The above is a C# escaped string that will match comment structures
not preceded by line comments "//".
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Natalia DeBow" <na***********@unisys.com> wrote in message
news:e9**************@TK2MSFTNGP11.phx.gbl...


Hi sevenfifteen,

Thanks so much for replying to my message. Your suggestion worked
indeed. Thanks!

I am stuck here on another problem, trying to come up with a regular
expression for the following case:
a. if a substring "/*" is detected, there is no "*/" that would follow;
b. if a substring "/*" is detected, there is neither "//" nor "/" that
preceeds it.

Part a is working fine, but when I add part b to it, things become
broken once again.

I have tried a few reg. ex.'s but nothing seems to work.

Here is what I have tried so far:
@"\s*(?!//?.*)(/[*])(?!.*[*]/)(?<comment>.*)"
@"\s*(?!.*//?)(/[*])(?!.*[*]/)(?<comment>.*)"
@"\s*(?<!//?.*)(?<=/[*])(?!.*[*]/)(?<comment>.*)"

Not sure where my logic is wrong.

Any help would be greatly appreciated!

Thanks,
Natalia

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 16 '05 #7
Eck, this one matches single line and multi-line comments.

Regex regex = new Regex(
"(?ms)" +
"^.*?((?<lineComment>//)|/\\*)" +
"(?<comments>.*?)" +
"(?(lineComment)$|\\*/)");

You can tell which you are matching by checking the lineComment
group for a value.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Justin Rogers" <Ju****@games4dotnet.com> wrote in message
news:uR**************@TK2MSFTNGP09.phx.gbl...
"(?ms)^.*?(?<!//[^\\n]*)/\\*(?<comments>.*)\\*/"

The above is a little better from what I can tell. You may
also need to make (?<comments>.*?), so that you don't
eat past the end of a comment.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Justin Rogers" <Ju****@games4dotnet.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Trying to match comments in /* */ pairs appears to be what you are doing.
Based on the semantics of something like c# it requires more logic than what
you are using.

"(?ms)^(?!.*//.*).*/\\*(?<comments>.*)\\*/"

The above is a C# escaped string that will match comment structures
not preceded by line comments "//".
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Natalia DeBow" <na***********@unisys.com> wrote in message
news:e9**************@TK2MSFTNGP11.phx.gbl...


Hi sevenfifteen,

Thanks so much for replying to my message. Your suggestion worked
indeed. Thanks!

I am stuck here on another problem, trying to come up with a regular
expression for the following case:
a. if a substring "/*" is detected, there is no "*/" that would follow;
b. if a substring "/*" is detected, there is neither "//" nor "/" that
preceeds it.

Part a is working fine, but when I add part b to it, things become
broken once again.

I have tried a few reg. ex.'s but nothing seems to work.

Here is what I have tried so far:
@"\s*(?!//?.*)(/[*])(?!.*[*]/)(?<comment>.*)"
@"\s*(?!.*//?)(/[*])(?!.*[*]/)(?<comment>.*)"
@"\s*(?<!//?.*)(?<=/[*])(?!.*[*]/)(?<comment>.*)"

Not sure where my logic is wrong.

Any help would be greatly appreciated!

Thanks,
Natalia

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Nov 16 '05 #8
Hi there,

Thanks so much, Justin, for your very helpful comments. They are
greatly appreciated!

I have another question for .NET RegEx experts.

I am reading in a C Sharp file line by line and I am trying to detect
comments that start with either // of ///. What I am particularly
interested is the comments themselves. I am interested in some stats in
regards to the amount of comments in the file (comment bytes).

So, I tried several regular expressions, but they don't seem to work in
all the cases.

Here are the cases that I need to cover:

a. /// comments or // comments
b. /// <xml-tag> comments </xml-tag>
c. /// <xml-tag> comments <another xml-tag> comments </another xml-tag>
comments </xml-tag>
d. /// <xml-tag>
e. /// </xml-tag>

I need to be able to capture the comments and not the xml tags.

Here are a few of regular expressions that I have tried but
unsuccessfully.

@"^.*?///?\s*((</?.+>)*(?<comments>.*))*$"
@"///?\s*(</?.+>)*(?<comments>.*)"

I am having difficulty capturing multiple comments if they are separated
by xml tags. For some odd reason, if I have more than one set of tags,
the returned result is always the right most set of comments.

Thanks so much for any input!
Natalia


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #9

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

Similar topics

3
by: Vibha Tripathi | last post by:
Hi Folks, I put a Regular Expression question on this list a couple days ago. I would like to rephrase my question as below: In the Python re.sub(regex, replacement, subject)...
5
by: Bradley Plett | last post by:
I'm hopeless at regular expressions (I just don't use them often enough to gain/maintain knowledge), but I need one now and am looking for help. I need to parse through a document to find a URL,...
10
by: Lee Kuhn | last post by:
I am trying the create a regular expression that will essentially match characters in the middle of a fixed-length string. The string may be any characters, but will always be the same length. In...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
5
by: Ryan | last post by:
HELLO I am using the following MICROSOFT SUGGESTED (somewhere on msdn) regular expression to validate email addresses however I understand that the RFP allows for "+" symbols in the email address...
7
by: norton | last post by:
Hello, Does any one know how to extact the following text into 4 different groups(namely Date, Artist, Album and Quality)? - Artist - Album Artist - Album - Artist - Album - Artist -...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
6
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not...
3
by: Zach | last post by:
Hello, Please forgive if this is not the most appropriate newsgroup for this question. Unfortunately I didn't find a newsgroup specific to regular expressions. I have the following regular...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.