1.如下string str="aa[IMG]http://wwww.sohu.com[/IMG]bb";if(str.Contains("[IMG]http://wwww.sohu.com[/IMG]")
{
    str.Replace("[IMG]http://wwww.sohu.com[/IMG]","<img src="http://wwww.sohu.com" />");
}2.同上
string str1="aaxxxbb"
string str2="";
string str3="
";
string str4="<a target=\"_blank\" href=\"http://www.sohu.com\">";
string str5="</a>";if(str1.Contains(str2)&&str1.Contains(str3))
{
    str.Replace(str2,str4);
    str.Replace(str3,str5);
}
这样就OK了,不用写正则表达式的.
用正则表达式写不出这东东.

解决方案 »

  1.   

    "aa[IMG]http://wwww.sohu.com[/IMG]bb".replace(/\[IMG\](.+?)\[\/IMG\]/gi, "<img src=\"$1\" \/>");
      

  2.   

    var str = "aa[IMG]http://wwww.sohu.com[/IMG]bb";
    str = str.replace(/^\[img\](.)+\[\/img\]$/ig,"<img src=\""+$1+"\" />");
    var str = "aaxxxbb";
    str = str.replace(/^\[url=(^\])+\](.)+\[\/url\]$/ig,"<a target=\"_blank\" href=\""+$1+"\">"+$2+"</a>");
      

  3.   

    var str1 = 'aa[IMG]http://wwww.sohu.com[/IMG]bb';
    alert(str1.replace(/\[IMG\](.*?)\[\/IMG\]/i,'<img src=\"$1\">'));
    var str2 = 'aaxxxbb';
    alert(str2.replace(/\[URL\=(.*?)\](.*?)\[\/URL\]/i,'<a target=\"_blank\" href=\"$1\">$2</a>'));
      

  4.   

    第二个是
    replace(/[URL=([^\]]+)]([\S\s]+?)[\/URL]/gi, "<a target=\"_blank\" href=\"$1\">$2<\/a>");
      

  5.   

    var str = "aa[IMG]http://wwww.sohu.com[/IMG]bb";
    str = str.replace(/^\[img\](.)+\[\/img\]$/ig,"<img src=\"$1\" />");
    var str = "aaxxxbb";
    str = str.replace(/^\[url=(^\])+\](.)+\[\/url\]$/ig,"<a target=\"_blank\" href=\"$1\">$2</a>");