读书人

听说这里的正则高手特多特来问一简单

发布时间: 2012-04-15 18:39:21 作者: rapoo

听说这里的正则高手特多,特来问一简单问题

HTML code
[color=#FF0000]xxx = true; // Remove old files[/color]// 5 minutes execution timeafdsfs        // Uncomment this one to fake upload time// asdfaf   // Uncomment this one to fake upload timefda     // Uncomment this one to fake upload time333


我想删除 有//的行 ,//有可能不是在开头 。参见红色部分,如果 //在表达式的后面,是不删除的。
正则应该如何写

[解决办法]

C# code
        string r = Regex.Replace(s, @"(?m)^\s*//.*$", "");
[解决办法]
探讨

C# code

string pat = @"(?is)^([^\S]*)//[^\r\n]*";
Regex rx = new Regex(pat);
string replacestr = rx.Replace(input, "$1");//input你的htmlcode

[解决办法]
str=Regex.Replace(str,"(?m)^\\s*//.*","");

读书人网 >C#

热点推荐