CSDN - 技术社区 - 问题 
 推荐给朋友 | 关闭窗口  
 
 
  
文本内容:  
...  
<td  width="10%">  
<a  href="/myplant/marvin/mols/nci1659.csmol">/myplant/marvin/mols/nci1659.csmol</a>  
</td>  
....  
 
要求:  
找到扩展名字中含有mol的哪个连接:如  
<a  href="/myplant/marvin/mols/nci1659.csmol">/myplant/marvin/mols/nci1659.csmol</a>  
这个连接  
然后把整个连接去掉,只剩连接的文件地址:  
/myplant/marvin/mols/nci1659.csmol  
谢谢  

解决方案 »

  1.   

    output = Regex.Replace(output,"(<a[^>]+()>)","");//去掉超链接
    output = Regex.Replace(output,"(</a+()>)","");
      

  2.   

    string regexStr = "href=\"([^\"]*mol[^\"]*)";
      

  3.   

    谢谢楼上的两位
    我现在是想把
    <a  href="/myplant/marvin/mols/nci1659.csmol">/myplant/marvin/mols/nci1659.csmol</a>  
    其中含有mol
    也就是mobydick大哥判断出的哪个把这整个连接cut掉,只提取出地址,转换为<script><src=/myplant/marvin/mols/nci1659.csmol></script>样式,谢谢
    完成马上放分,俺见正则就流bixue
      

  4.   

    string strReplaceTemplet = @"<script><src={1}></script>";string regexStr = string regexStr = "href=\"([^\"]*mol[^\"]*)";string yourStr = @"...  
    <td  width=""10%"">  
    <a  href=""/myplant/marvin/mols/nci1659.csmol"">/myplant/marvin/mols/nci1659.csmol</a>  
    </td>  
    .... "MatchCollection mc = Regex.Matches(yourStr, regexStr);
    foreach(Match m in mc)
    {
        string temp = m.Groups[1].Value;
        temp = String.Format(strReplaceTemplet, temp);
    }
      

  5.   

    这样更简单:
    string regexStr = @"<a\s*href=\"([^\"]*mol[^\"]*)\"\s*>[^<]*</a>";
    string strReplaceTemplet = @"<script><src=$1></script>";string yourStr = ....string temp  = Regex.Replace(yourStr, regexStr, strReplaceTemplet);
      

  6.   

    顺便问一下:
     <td width="10%">/myplant/marvin/mols/nci1659.csmol </td>
    就是<td></td>间含有mol的怎么取出/myplant/marvin/mols/nci1659.csmol值
    谢谢
      

  7.   

    谢谢
    我替换后的结果是:
    <a href="/myplant/marvin/mols/nci1659.csmol"<script LANGUAGE='JavaScript1.1' SRC='d/marvin.js'></script>
    <script LANGUAGE='JavaScript1.1'>
    mview_param('mol', /myplant/marvin/mols/nci1659.csmol);
    mview_end();</script></a>
    怎么只有一个<script LANGUAGE='JavaScript1.1'>
    mview_param('mol', /myplant/marvin/mols/nci1659.csmol);
    mview_end();</script>
    就是先把href去掉然后替换
    (可以转分)