• C#正则表达式校验


     static void Main(string[] args)
            {
                WebClient wc = new WebClient();
                //要把网页以字符串的形式下载下来
                string htmlstr = wc.DownloadString("http://zhidao.baidu.com/link?url=6kcGgrcqb84u-4NDe7aoUSCdmHVt-2DbKffrD5DiwZodgalkfPbnbhD1Hy2v_By4k2IN6tYtFt59Qwor7HRLpHflaaHnoXGYR9dhGX1r55K");
                MatchCollection mc = Regex.Matches(htmlstr, "[0-9a-zA-Z_.-]+@[0-9a-zA-Z_.]+([.][a-zA-Z]+){1,2}");
                foreach (Match item in mc)
                {
                    if (item.Success)//是否匹配成功,写上更好
                    {
                        Console.WriteLine(item.Value);
                    }
                }
                Console.ReadKey();
    
            }
            static void Main(string[] args)
            {
                string eamil = Console.ReadLine();
                //是否匹配
                bool result = Regex.IsMatch(eamil, "[0-9a-zA-Z_.-]+@[0-9a-zA-Z_.]+([.][a-zA-Z]+){1,2}");
    
                //获取匹配的结果
                Match mt = Regex.Match(eamil, "[0-9a-zA-Z_.-]+@[0-9a-zA-Z_.]+([.][a-zA-Z]+){1,2}");
    
                Console.WriteLine(result);
                Console.WriteLine(mt.Value);
                Console.ReadKey();
    
    
            }

    获取网页的图片:

    using System;
    using System.Net;
    using System.Text;
    using System.Text.RegularExpressions;
    
    namespace GetPictures
    {
        class Program
        {
            static void Main(string[] args)
            {
                //首先下载页面
                WebClient wc = new WebClient();
                wc.Encoding = Encoding.UTF8;
                string html = wc.DownloadString("https://www.camarts.cn/archives/3020.html");
                MatchCollection mc = Regex.Matches(html, "<img\sclass="aligncenter\ssize-full\swp-image-[0-9]{4}?"\ssrc="(.+?)".+?>");
    
    
    
                //遍历匹配的内容
                int i=0;
                foreach (Match item in mc)
                {
                    i++;
                    if (item.Success)
                    {
                        string path = item.Groups[1].Value;//图片下载地址
    
                        //下载图片
                        if(i%2==0)
                        {
                        wc.DownloadFile(path, @"D:高清图片" + i + ".jpg");
                        Console.WriteLine(""+i/2);//进度 
                        }
                        /*
                         <img class="aligncenter size-full wp-image-3021" src="https://dn-ssl-img-camarts.qbox.me/2014/07/IMG_9659.jpg?imageView/2/w/800/h/800/q/90" data-original="https://dn-ssl-img-camarts.qbox.me/2014/07/IMG_9659.jpg?imageView/2/w/800/h/800/q/90" alt="IMG_9659" width="800" height="533" srcset="https://dn-ssl-img-camarts.qbox.me/2014/07/IMG_9659.jpg 800w, https://dn-ssl-img-camarts.qbox.me/2014/07/IMG_9659-150x99.jpg 150w, https://dn-ssl-img-camarts.qbox.me/2014/07/IMG_9659-300x199.jpg 300w, https://dn-ssl-img-camarts.qbox.me/2014/07/IMG_9659-450x300.jpg 450w" sizes="(max- 800px) 100vw, 800px" style="display: block;">
                         <img class="aligncenter size-full wp-image-3022" src="https://dn-ssl-img-camarts.qbox.me/2014/07/IMG_9668.jpg?imageView/2/w/800/h/800/q/90" data-original="https://dn-ssl-img-camarts.qbox.me/2014/07/IMG_9668.jpg?imageView/2/w/800/h/800/q/90" alt="IMG_9668" width="800" height="533" srcset="https://dn-ssl-img-camarts.qbox.me/2014/07/IMG_9668.jpg 800w, https://dn-ssl-img-camarts.qbox.me/2014/07/IMG_9668-150x99.jpg 150w, https://dn-ssl-img-camarts.qbox.me/2014/07/IMG_9668-300x199.jpg 300w, https://dn-ssl-img-camarts.qbox.me/2014/07/IMG_9668-450x300.jpg 450w" sizes="(max- 800px) 100vw, 800px" style="display: block;">
                         <img\sclass="aligncenter\ssize-full\swp-image-[1-9]+"\ssrc="(.+.+?)".+?>                
                         */
                    }
                }
                Console.ReadKey();
            }
        }
    }
  • 相关阅读:
    打赏
    996315便捷扫码接口的使用方法
    openjdk ImageIO.write()时出现Invalid argument to native writeImage
    CentOS7通过rpm包升级openssh8.8
    python docx转pdf
    python生成币私钥公钥
    二叉树的非递归后序遍历算法
    STM32引脚做输入时,有开漏,浮空输入,弱上拉,弱下拉,等多种方式,如何选择????
    TLC2551驱动问题
    connot launth the modelsimaltera softwarre because you did not specify the path to the executables of the modelsimaltera softwarre
  • 原文地址:https://www.cnblogs.com/ink-heart/p/5900151.html
Copyright © 2020-2023  润新知