吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2485|回复: 7
收起左侧

[其他转载] 正则表达式之AAA云推荐码的获取

[复制链接]
遗憾迟香 发表于 2020-4-27 20:23
本帖最后由 遗憾迟香 于 2020-4-27 20:32 编辑

第一次练习C#的正则表达式AAA云推荐码的格式为:
AAAYUN{0}-{1}
{0}为13个字符,{1}为八位日期
正则表达式如下
AAAYUN.{13}-\d{8}
源码:
[C#] 纯文本查看 复制代码
        /// <summary>
        /// 匹配推荐码
        /// </summary>
        /// <param name="s">获取到的网页源码</param>
        private static void GetCode(string s)
        {
            Regex rg = new Regex(@"AAAYUN.{13}-\d{8}", RegexOptions.Multiline | RegexOptions.Singleline);
            MatchCollection matches = rg.Matches(s);
            DateTime dt = DateTime.Now;
            foreach (Match item in matches)
            {
                string value = item.Value;
                DateTime time = DateTime.ParseExact(value.Substring(20, 8), "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
                if (time > dt)//排除已过期的推荐码
                    Console.WriteLine(value);
            }
        }
        /// <summary>
        /// Get请求
        /// </summary>
        /// <param name="url">Url</param>
        /// <returns></returns>
        private static string Get(string url)
        {
            string message = string.Empty;
            HttpWebRequest request;
            try
            {
                request = (HttpWebRequest)WebRequest.Create(url);
                request.Accept = "text/html, application/xhtml+xml, */*";
                request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)";
                request.KeepAlive = true;
                request.ProtocolVersion = HttpVersion.Version11;
                request.Timeout = 20000;
                ServicePointManager.Expect100Continue = false;
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream responseStream = response.GetResponseStream();
                StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                message = reader.ReadToEnd();
                reader.Close();
                responseStream.Close();
            }
            catch (Exception err)
            {
                message = err.Message;
            }
            return message;
        }

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

Mudai- 发表于 2020-4-27 20:28
?????????????
色色 发表于 2020-4-27 20:43
 楼主| 遗憾迟香 发表于 2020-4-27 20:56
色色 发表于 2020-4-27 20:43
这个服务器咋样 好用吗 延期方便吗

我刚注册,明天零点才能激活
1ander 发表于 2020-4-27 22:36
认真学习一下,感谢楼主分享
YaSaXii 发表于 2020-4-27 22:46
请问代码是怎么用的呢,还需要主函数调用才能运行吗,小白的疑惑
uuu4758 发表于 2020-12-17 17:06
学习学习,感谢楼主
他是传说 发表于 2020-12-17 19:13
学习了!感谢大神
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-27 11:58

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表