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" <Justin@games4dotnet.com> wrote in message
news:uRbPX1OSEHA.3504@TK2MSFTNGP09.phx.gbl...[color=blue]
> "(?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" <Justin@games4dotnet.com> wrote in message
> news:%23$ifNdOSEHA.3944@tk2msftngp13.phx.gbl...[color=green]
> > 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" <natalia.debow@unisys.com> wrote in message
> > news:e9kEdEOSEHA.1276@TK2MSFTNGP11.phx.gbl...[color=darkred]
> > >
> > >
> > > 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![/color]
> >
> >[/color]
>
>[/color]