请问,String.Replace(string,string)这个方法可以使用正则表达式么?我是新手,没用过正则,我只是想在一段字符串里面将<ima.....>
这样的图片html代码全部替换成空格,另外,正则是这么写么 <ima(\S*?)[^>]*>.*?</\1>|<.*? />    谢谢

解决方案 »

  1.   

    使用正则,要使用Regex类
    Regex.Replace()有多种重载,具体看msdn
      

  2.   

    String类成员:http://msdn.microsoft.com/zh-cn/library/system.string_members(VS.85).aspx
    Regex类成员:http://msdn.microsoft.com/zh-cn/library/system.text.regularexpressions.regex_members(VS.85).aspx
      

  3.   

    using System.Text.RegularExpressions;Regex re = new Regex("你的表达式");
    re.Replace(...)
      

  4.   

    string test = ...........;
    Match m = Regex.Match(test, @"<img[^>]*?src=""(?<img>[^""]*)""[^>]*>(\s*<(?!img)[^>]*>\s*)", RegexOptions.IgnoreCase);
    if (m.Success)
        String s=(m.Groups["img"].Value);
    这个是我前两天 问过的问题,虽和你的不大一样,但上面的正则,能取出  
    <IMG id=ryxp onclick="hoto('0010091','9')" src="CXOutputDetail_files/viewattch.jpg" width=130>
    里面的CXOutputDetail_files/viewattch.jpg,
    在代码里可以看到,是取 的 img组的内容,而如果你用String s=img.value就能得到整个img的内容了
    替换的话 就是 
    Match mReplace=Regex.Replace(s,"");
    if (mReplace.Success)
        String s=mReplace.Value;