Thanks for all of the information I think I might have an expression that
will work for you. It at least works for all of the examples you provided.
There may be some problems if new lines are allowed in string identifiers.
@"^((?>[^'\-]*?'.*?')*)([^'\-]*)/\*"
This should eat up all character starting the beging of line that are not
either ' or - unless there is a matching ' or - appers inside matching '.
I tested this with version 1.1 of the framework.
Again let me know if this does not work for you.
Thanks,
Ryan Byington [MS]
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
--------------------
| From: "Ali Eghtebas" <al***@home.se>
| References: <#F**************@TK2MSFTNGP12.phx.gbl>
<N6**************@cpmsftngxa06.phx.gbl>
| Subject: Re: What's your opinion RegEx Gurus?
| Date: Thu, 11 Sep 2003 11:38:35 +0200
| Lines: 41
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <u$**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.general
| NNTP-Posting-Host: as19-6-8.mt.g.bonet.se 194.236.117.158
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:108113
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| Thank you Ryan for replying as you are the only one who replied to this
post
| so far.
| However I must say that you've misunderstood what I wanted.
| The expression you've provided will only NOT match, matchable strings
| stating with a -
| While what I want is to match any /* that is not within a commented line
| by -- since
| -- is the start of a commented line and not necessarily right at the start
| of the line. E.g.:
| -- This is a comment.
| code code code -- This is a comment.
| Furthor more /* should not be matched if it between two string identifier
| characters
| which is the character ' in T-SQL e.g. ' This is just a string
expression.'.
| '/*' <= not a valid match
| '' /* <= is a valid match since /* is not within the string
expression.
| And there is more... if the line comment character -- is itself within ''
| then it is just part of a string expression and not a start of a comment.
| All this can be understood by the following examples:
| ''' /* A <= Not a match since the third ' is the start of a string
| expression, hence /* A is assumed to be within a string.
| ''-- /* B <= Not a match since /* B is in a commented line by --
| --'' /* C <= Not a match since /* C is in a commented line by --
| '--' /* D <= A match since /* D is neither wihin a string
expression
| nor commented by -- since the -- is itself within a string expression
| between ''.
| '--''' /* E <= A match since /* E is neither wihin a string
| expression nor commented by -- since the -- is itself within a string
| expression between ''. And the last '' is just an empty string.
| '--'' /* F <= Not a match since the last ' is the start of a string
| expression, hence /* F is assumed to be within a string.
|
| Using the expression below will only catch /* D and /* E.
|
"(?<=^(?:[^'\r]*'[^'\r]*')*?[^'\r]*)(?<!^(?:[^'\r]*'[^'\r]*')*?--.*)/\*.*?$"
| With Multiline option on.
|
| --
| Thanks in advance
| Ali Eghtebas Sweden
|
|
|