文件名如/ABC/xxxxx.shtml
1)除了文件名里面包含Leaveword.shtml和-m-2.shtml的扩展名,其他的文件都要替换成/ABC/xxxxx.html格式请问正则表达式怎么书写正则表达式

解决方案 »

  1.   

    HTML文件代码里面有很多的超链接,其中有一种.shtml格式的超链接地址
    现在要求如下:
    1>特定知道的不需要替换的网址
      /Tools/Leaveword.shtml
      /Tools/OK.shtml
    2>模糊但是需要替换的网址格式
      /ABC/xxxxxx.shtml需要替换为/ABC/xxxxxx.html,但是遇到/ABC/xxxxxx-m-2.shtml,不需要替换成/ABC/xxxxxx-m-2.html
      /CDE/xxxxxxx.shtml需要替换为/CDE/xxxxxxx.html,但是遇到/CDE/xxxxxx-m-2.shtml,不需要替换成/CDE/xxxxxx-m-2.html请高手告知正则表达式怎么书写比较好。
      
      

  2.   

    string str="/Tools/Leaveword.shtml
      /Tools/OK.shtml
      /ABC/xxxxxx.shtml,ttryrt,/ABC/xxxxxx-m-2.shtml
      /CDE/xxxxxxx.shtml,";
    str=Regex.Replace(str,"(?<=/x{1,}\.)shtml","html");
      

  3.   

    To:Chinajiyong /ABC/xxxxxx.shtml,ttryrt,/ABC/xxxxxx-m-2.shtml
    /CDE/xxxxxxx.shtml
    补充说明
    xxxxxx.shtml的xxxxxx是动态的字母,如abcdefg.shtml,dsajdsjajd.shtml等等,并不是说网页文件名称为:xxxxxx.shtml,可能有点难度,请问正则表达式如何书写。
      

  4.   

    string str=@"/Tools/Leaveword.shtml
      /Tools/OK.shtml
      /ABC/xxxxxx.shtml,ttryrt,/ABC/xxxxxx-m-2.shtml
      /CDE/xxxxxxx.shtml,";
                str = Regex.Replace(str, @"(?i)(?<=/(?:(?![^.\s]*?(?:Leaveword|OK|-m-2))[^.]+?)\.)shtml", "html");
                /*
               /Tools/Leaveword.shtml
      /Tools/OK.shtml
      /ABC/xxxxxx.html,ttryrt,/ABC/xxxxxx-m-2.shtml
      /CDE/xxxxxxx.html,
                 */
      

  5.   

    改一下就行了啊
    (?is)(?<=/[a-z]{1,}\.)shtml
    string str="/Tools/Leaveword.shtml
      /Tools/OK.shtml
      /ABC/xxxxxx.shtml,ttryrt,/ABC/xxxxxx-m-2.shtml
      /CDE/xxxxxxx.shtml,";
    str=Regex.Replace(str,"(?is)(?<=/[a-z]{1,}\.)shtml","html");
      

  6.   

    To:Return_false当需要替换的文本只有一行字符串,没有问题,完全正确,但是需要替换的文本使用文件对象把一个网页拿出来的时候进行替换,如
                string filename = "QiYeYouJuBiaoZhunBan3G.html";
                FileStream file = new FileStream(Server.MapPath(filename), FileMode.Open);
                StreamReader streamReader = new StreamReader(file);
                string ReadText = streamReader.ReadToEnd();
    就失去效果了,全部的.shtml被替换成了.html,调试了好久,非常奇怪,为什么一行有效,从一个网页里面调用进行替换就失效。To:Chinajiyong
    发现网址里面有数字,就保留.shtml格式,但是里面没有数字,就替换成.html格式。我现在的需求就是需要保留的网址包含如下特征:
    网址里面包含:[|代表或者包含]
    Leaveword|-m-1|-m-2|-m-3|-m-4|-m-5|-m-6|-m-7|Rss-|News-|Product-|Project-|Help-|Agent-|Job-  这种格式
    如xxxxxx-m-2.shtml,Product-absnei8d.shtml,News-absnei8d.shtml请问正则表达式怎么书写。