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         }
  • 相关阅读:
    PTA L1-002 打印沙漏 (20分)
    音乐研究
    LeetCode 155. 最小栈
    LeetCode 13. 罗马数字转整数
    LeetCode 69. x 的平方根
    LeetCode 572. 另一个树的子树
    errno错误号含义
    僵尸进程和孤儿进程
    TCP和UDP相关概念
    图相关算法
  • 原文地址:https://www.cnblogs.com/suanshun/p/5337779.html
Copyright © 2011-2022 走看看