0

I would like to remove all comments from a PHP source file from within a VB.NET application. Another stackoverflow question showed how to do this in C# code

I came up with this conversion, but it does not work unfortunately:

Dim blockComments As String = "/\*(.*?)\*/"
Dim lineComments As String = "//(.*?)\r?\n"
Dim strings As String = """((\\[^\n]|[^""\n])*)"""
Dim verbatimStrings As String = "@(""[^""]*"")+"
regex = New Regex(blockComments & "|" & lineComments)
srcT = regex.Replace(srcT, "")
Community
  • 1
  • 1
exim
  • 606
  • 1
  • 8
  • 24
  • 1
    Wheres the problem? What did you try to solve it? What other solutions have you looked at? – dognose Jun 07 '13 at 09:17
  • It helps to specify the exact problems you are having, saying "it does not work unfortunately" doesn't give us much information. – Walt Ritscher Jun 07 '13 at 22:24

1 Answers1

0

You need to pass the flag RegexOptions.Singleline when constructing the Regex object. Otherwise, the block-comments can't span multiple lines.

regex = New Regex(blockComments & "|" & lineComments, RegexOptions.Singleline)

The . normally matches any character except newline (\n). The RegexOptions.Singleline flag makes it match any character, including newline.

Markus Jarderot
  • 86,735
  • 21
  • 136
  • 138