读书人

C#靠山正则获取内容替换(2)

发布时间: 2013-07-09 09:50:47 作者: rapoo

C#后台正则获取内容替换(2)
<embed src="/editor/kindeditor/attached/media/20130626/20130626065054_3546.avi" type="video/x-ms-asf-plugin" width="550" height="400" autostart="false" loop="true" />

<embed src="/editor/kindeditor/attached/media/20130626/20130626065054_3546.avi" type="video/x-ms-asf-plugin" width="550" height="400" autostart="true" loop="true" />

<embed width="550" height="400" autostart="false" loop="true" type="application/x-shockwave-flash" src="/zhanhua/kindeditor/asp.net/kindeditor/attached/media/20130626/20130626141327_4506"></embed>

<embed width="550" height="400" autostart="true" loop="true" type="application/x-shockwave-flash" src="/zhanhua/kindeditor/asp.net/kindeditor/attached/media/20130626/20130626141327_4506"></embed>
哭了我,用了下编辑器居中。
取出src。用flash播放器代替embed标签,取到的src值插入到flash的src中。两种情况。
我的逻辑思维能力写不了这么复杂的正则。希望大大们能帮忙。 C# 正则
[解决办法]
至少你要表达清楚你想要什么
[解决办法]
上个帖子已经有答案了,正则里面的分组2便是src ,那么替换的字符串的 $2便是,放在你需要的位置即可

string regex = @"(?i)<embed\b[^>]*?src=(['""]?)([^'""]+)\1[^>]*?autostart=\1(?:true
[解决办法]
false)\1[^>]*?>";
string repalce_str = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"...\"><param name=\"movie\" value=\"$2\" /><param name=\"quality\" value=\"high\"/><embed src=\"$2\" type=\"video/x-ms-asf-plugin\" /></object>";
//string flashStr=string.Format
string result = Regex.Replace(tempStr, regex, repalce_str);

读书人网 >asp.net

热点推荐