Answer the question
In order to leave comments, you need to log in
Help with regulars
There is a task - to remove
all
comments
from the php code. I process
regulars
with the regexp .NET 3.5 class
.
if (ext.ToLower() == "php" )
{
string content = File.ReadAllText(file, System.Text.Encoding.UTF8);
content = Regex.Replace(content, @"\/\/.*(\r?\n)?", @"");
content = Regex.Replace(content, @"\/\*(.*(\r?\n)?)*.*\*\/", @"");
content = Regex.Replace(content, @"\r?\n", @" ");
File.WriteAllBytes(dst + fileName, System.Text.Encoding.UTF8.GetBytes( content ));
}
}
Answer the question
In order to leave comments, you need to log in
It is convenient to delete comments by PHP itself “php -w”, however, it also cuts spaces.
IMHO - what you need, it is enough to have a php binary.
If I were you, I would change the regular expressions to take into account several lines, then there would be no need to insert \r\n\s and the like into them. And secondly, you will not achieve the correct work with regulars:
\\ comment
$a = '\\ not comment'; - такое Вы учитываете?
Purely regular expressions will be very difficult, especially parsing something like get(' example.com ');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question