zoukankan      html  css  js  c++  java
  • 常用的正则表达式

    【提取内容图片地址】

     1         /// <summary>
     2         /// 取得HTML中所有图片的 URL。
     3         /// </summary>
     4         /// <param name="sHtmlText">HTML代码</param>
     5         /// <returns>图片的URL列表</returns>
     6         public static string[] GetHtmlImageUrlList(string sHtmlText)
     7         {
     8             // 定义正则表达式用来匹配 img 标签
     9             Regex regImg = new Regex(@"<img[^<>]*?src[s	
    ]*=[s	
    ]*[""']?[s	
    ]*(?<imgUrl>[^s	
    ""'<>]*)[^<>]*?/?[s	
    ]*>", RegexOptions.IgnoreCase);
    10 
    11             // 搜索匹配的字符串
    12             MatchCollection matches = regImg.Matches(sHtmlText);
    13             int i = 0;
    14             string[] sUrlList = new string[matches.Count];
    15             // 取得匹配项列表
    16             foreach (Match match in matches)
    17                 sUrlList[i++] = match.Groups["imgUrl"].Value;
    18             return sUrlList;
    19         }

    【去掉字符串中的数字】

     1         /// <summary>  
     2         /// 去掉字符串中的数字  
     3         /// </summary>  
     4         /// <param name="key"></param>  
     5         /// <returns></returns>  
     6         public string GetNumber(string key)
     7         {
     8             return Regex.Replace(key, @"([1-9]+[0-9]*|0)(\.[\d]+)?", "");
     9 
    10         }
  • 相关阅读:
    今年要读的书
    java多线程
    json-lib 使用教程
    tomcat原理
    静态long类型常量serialVersionUID的作用
    使用junit4测试Spring
    MySQL各版本的区别
    spring mvc 下载安装
    hibernate、struts、spring mvc的作用
    【面试】hibernate n+1问题
  • 原文地址:https://www.cnblogs.com/suanshun/p/5337779.html
Copyright © 2011-2022 走看看