正则表达式匹配代码中的具体注释 [英] Regex to match specific comments in code
问题描述
有没有正规的专家谁可以帮助我清理以下源代码?我将通过一些现有的代码,我看到类似于以下几个实例:
public enum Numbers
{
///< summary>
/// One = 1,
///< / summary>
One = 1,
///< summary>
/// Two = 2,
///< / summary>
Two = 2,
///< summary>
/// Three = 3,
///< / summary>
Three = 3,
///< summary>
/// Four = 4但不要使用它,因为它会破坏一切,
///< / summary>
Four = 4,
}
除非有人能告诉我对于1-3是必要的,我想做一个find / replace(删除)所有的注释,不添加任何值的代码。从浏览代码,我认为可以放心,假设任何类似于/// word = number的行都可以替换。清理,我认为它应该看起来像:
public enum数字
{
One = 1,
Two = 2,
Three = 3,
///< summary>
/// Four = 4但不要使用它,因为它会破坏一切,
///< / summary>
Four = 4,
}
通过帮助我,你真的在帮助自己。因为谁知道,有一天你可能会维护这个代码!
使用VS2008 FindAndReplace我试过这个工作; >
查找内容:
\\< summary\>。* \\\
。* \ =:b:d [:b,] * \\\
。* \< \ / summary \> \\\
替换为:
(空)
strong>
正则表达式
Are there any regex experts who can help me clean up the following source code? I'm going through some existing code and I see several instances similar to the following:
public enum Numbers
{
/// <summary>
/// One = 1,
/// </summary>
One = 1,
/// <summary>
/// Two = 2,
/// </summary>
Two = 2,
/// <summary>
/// Three = 3,
/// </summary>
Three = 3,
/// <summary>
/// Four = 4 but don't use this because it will break everything,
/// </summary>
Four = 4,
}
Unless someone can tell me that the comments for 1-3 are necessary, I'd like to do a find/replace (remove) on all of the comments that don't add any value to the code. From browsing the code I think it's safe to assume that any line that resembles "/// word = number," can be replaced. Cleaned up, I think it should look like:
public enum Numbers
{
One = 1,
Two = 2,
Three = 3,
/// <summary>
/// Four = 4 but don't use this because it will break everything,
/// </summary>
Four = 4,
}
Your help is greatly appreciated! And by helping me, you are really helping yourself. Because who knows, someday you might be maintaining this very code!
With VS2008 FindAndReplace I tried this and worked;
Find what:
/// \<summary\>.*\n.*\=:b:d[:b,]*\n.*\<\/summary\>\n
Replace with:
(empty)
Use:
Regular expressions
这篇关于正则表达式匹配代码中的具体注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!