日期:2014-05-20  浏览次数:20896 次

正则表达式 求教
[MP=480,360,true]http://www.abc.com/watch?v=eMcvUaB9FgE[/MP]
上面这段如何用正则搞成

<object   width= "480 "   height= "360 "> <param   name= "movie "   value= "http://www.youtube.com/v/eMcvUaB9FgE "> </param> <param   name= "wmode "   value= "transparent "> </param> <embed   src= "http://www.youtube.com/v/eMcvUaB9FgE "   type= "application/x-shockwave-flash "   wmode= "transparent "   width= "425 "   height= "350 "> </embed> </object>

------解决方案--------------------
using System.Text.RegularExpressions;


string S = @ "[MP=480,360,true]http://www.abc.com/watch?v=eMcvUaB9FgE[/MP] ";


S = Regex.Replace(S, @ "\[MP=*([0-9]*),*([0-9]*),*([true|false]*)\](.[^\[]*)\[\/MP] ", @ " <object align= 'middle ' classid= 'CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 ' class= 'OBJECT ' id= 'MediaPlayer ' width= '$1 ' height= '$2 '> <PARAM NAME= 'AUTOSTART ' VALUE= '$3 '> <param name= 'ShowStatusBar ' value=-1> <param name=Filename value=$4> <embed type=application/x-oleobject codebase= 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 ' flename= 'mp ' src= '$4 ' width= '$1 ' height= '$2 '> </embed> </object> ");