RegEx删除/** */和//** **//php注释 [英] RegEx to remove /** */ and // ** **// php comments
问题描述
此处是ReGex新手.
ReGex newbie here.
我需要使用RegEx从PHP文件中删除两个不同的样式注释.
I need to remove two different style comments from PHP files using RegEx.
我发现此表达式可在BBEdit文本编辑器中运行:
I've found this expression to run in the BBEdit text editor:
\/\*[\s\S]*?\*\/
并删除第一种样式的注释,如下所示:
and it removes comments in the first style, like below:
/** This comment gets removed with my regex */
但是它不会删除这些样式注释:
But it doesn't remove these style comments:
// ** This comment has the double leadng-trailng slashes ** //
我不知道为什么混合使用两种不同类型的注释,并且只有少数//
条注释,但是我需要将其全部删除.
I don't know why there is a mix of the two different types of comments, and there are only a few of the //
comments, but I need to delete them all.
在搜索中添加另一个斜杠,即
Adding another slash to the search, i.e.
\/\\*[\s\S]*?\*\/
使表达式变得贪婪,并删除非注释代码中的单斜杠.一个有效的表达式显然需要比这更多的复杂性:)
makes the expression greedy and it removes single slashes in non-commented code. A working expression will require obviously more complexity than that :)
推荐答案
~//?\s*\*[\s\S]*?\*\s*//?~
这有效.只需在答案中添加另一个\和空格键即可.
This works.Just added another \ and space eaters to your answer.
请参阅演示.
http://regex101.com/r/lK9zP6/6
这篇关于RegEx删除/** */和//** **//php注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!