captain monk
captain monk

Reputation: 727

Flex regex multy line comment

Can someone explain to me the difference,i've been testing for over 2 hours now...

 This regex \"(.|\n)*\" gets everything inside " " (along with the " ").

 This regex "//".*$ gets a single line comment(c).

`But the regex \/\*(.|\n)*\*\/ doesn't get a multy line comment

instead it gets too many, i don't even understand. Can someone explain to me the difference?Also [^"] means everything except " is it possible to write [^*/] or it takes * and / as not connected characters?By the way i run all these on VS2008(using flex and bison). I found examples that doesn't work on VS2008, so if someone knows a really good site that explains regex share it with me cause i feel like i'm lost in a labyrinth. Thank you for your time!

Upvotes: 1

Views: 110

Answers (1)

jeshu911
jeshu911

Reputation: 94

try using below regEx to get the commented part along with start and end block of comment :

b = /\/\*(.)*(\n)?(.)*\*\/g

e.g

a = "some of my text/* hello this is comment\nthis comment is not good*/. Text cont."
b = /\/\*(.)*(\n)?(.)*\*\/g
a.replace(b, "")
[output ] : "some of my text. Text cont."

hope this will help you.

this expression is for JS. I think in your case you should try

"\/\*((.)*(\n)?)*(.)*\*\/"

Upvotes: 1

Related Questions