摘要:(?.*?)\=(?.*?); cookie.Add(new CookieList() { Key = "\1", Value = "\2", Domain = "xxx.com" });
阅读全文
摘要://(?<=头部标记)[\\s\\S]*?(?=尾部标记) //|<script id=\"ad] string patten = "(?<=<div ad_dot_url)[\\s\\S]*?(?=<div id=\"sc|<script id=\"ad)"; html = Regex.Repla
阅读全文
摘要:如题,将 {OUTSCIPTE} 关键词后的所有内容替换为string.Empty(包含关键字)这个正则该怎么写?我是 {OUTSCIPTE}(.*)$ 写的但是什么反应也没有string str=Regex.Replace("字符串",@"(?exp)或者(?'name'exp)其中name是分组...
阅读全文
摘要:string pattrn2 = "(?[\\s\\S]*?)"; MatchCollection results = Regex.Matches(IPstrLine, pattrn, RegexOptions.IgnoreCase); ...
阅读全文
摘要:简介本文介绍net处理html页面元素的工具类(HtmlAgilityPack.dll)的使用,用途比较多的应该是例如采集类的功能,采集到的html字符串要怎样处理是一个头痛的问题,如果是截取就太麻烦了而且容易出错。所有就用到本文的第三方dll来处理了。下载下载地址:http://htmlagilitypack.codeplex.com/点击“download”按钮直接下载。使用1.添加HtmlAgilityPack.dll引用(引用类using HtmlAgilityPack;)。2.简单根据html中input的id获取value代码如下:// 模拟用户请求WebClient webCli
阅读全文
摘要:去年写过一篇文章《解析HTML最好的类还是微软自己的》,回复中有朋友提到可以使用HtmlAgilityPack来进行HTML的解析。当时只是匆匆的测试了一下,发现HtmlAgilityPack得到的InnerText中有很多的不干净的script、样式内容,就断定“不是很满意,解析DiscuzNT!论坛的帖子页面的时候有问题,没法正确得到Body.InnerText的内容,有很多残留html、js代码夹杂在其中,解析的不是很好。”传智播客.net培训学院内部有一个工具是我开发的,其中的HTML解析部分就是我使用MSHTML完成的,但是今天发现这个软件一个Bug,是MSHTML的HTMLDocu
阅读全文
摘要:大家都知道正则表达式的用处,平时多积累,用时也省心。 以下是我少了不少时间整理的C#的正则表达式,新手朋友注意一定要手册一下哦,这样可以节省很多写代码的时间。 只能输入数字:"^[0-9]*$"。 只能输入n位的数字:"^\d{n}$"。 只能输入至少n位的数字:"^\d{n,}$"。 只能输入m~n位的数字:。"^\d{m,n}$" 只能输入零和非零开头的数字:"^(0|[1-9][0-9]*)$"。 只能输入有两位小数的正实数:"^[0-9]+(.[0-9]{2})?$"
阅读全文
摘要:一、组的分类 正则中的组有捕获组和非捕获组,而捕获组又分为普通的捕获组和命名捕获组,分别为 捕获组:(exp) 命名捕获组:(? <name> exp) 非捕获组:(?:exp) 二、组的作用 1、捕获组的作用 捕获组的作用是将正则表达式exp匹配到的内容保存到组里,供以后使用 比如这样一个字符串: <ahref="http://bbs.csdn.net"title="床上等你"> CSDN </a> 我想得到网址,而它符合的规则是在 <a...> 标签内,那就可以这样做 C# code string te
阅读全文
摘要:string pattenhref = "<a([^>])*>"; string pattenhrefend = "</a([^>])*>"; Regex rg = new Regex(pattenhref, RegexOptions.Multiline | RegexOptions.Singleline); MatchCollection m = rg.Matches(strtext); for (int i = 0; i < m.Count; i++) { MessageBox.Show(m[i].Resul
阅读全文
摘要:http://see.xidian.edu.cn/cpp/html/1439.html
阅读全文
摘要:public static string NoHTML(stringHtmlstring) { //删除脚本 Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase); //删除HTML Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", ...
阅读全文
摘要:using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Text.RegularExpressions;public part
阅读全文
摘要:public string GetUrlDomainName(string url) { //获取域名的正则表达式 string p = @"http://[^\.]*\.(?<domain>[^/|?]*)"; Regex reg = new Regex(p, RegexOptions.IgnoreCase);//不区分大小写匹配 //正则表达式匹配结果 Match m = reg.Match(url); //返回匹配结果值 ...
阅读全文
摘要:public string GetUrlDomainName(string url) { //获取域名的正则表达式 string p = @"http://[^\.]*\.(?<domain>[^/|?]*)"; Regex reg = new Regex(p, RegexOptions.IgnoreCase);//不区分大小写匹配 //正则表达式匹配结果 Match m = reg.Match(url); //返回匹配结果值 return m.Groups["domain"].Value; }获取域名就不说了吧 下面是正则的使用 publi
阅读全文
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using System.Text.RegularExpressions;namespace rexurl{ class Program { static void Main(string[] args) { string regex = @"(?i)http://(\w+\.){2,3}(com(\.cn)?|cn|net)\b"; string content = "
阅读全文
摘要:数据库里面的是 <font color='ff0000'>最新国内外新闻..... </font> 我要他显示出来是 <font color='ff0000'>最新国内外.(只显示5个字) </font> <font color='ff0000'>这个是不定的,我要的是这个<font color='ff0000'></font>中间只显示5个文字怎么实现呢... --> 转移QQ号:21993961时间:2008-08-27 17:34--&
阅读全文
摘要:两个特定字符串带有符号的;例如"PROMOTEDTYPE":"260","MEMBERID":"24912496","SHOPTYPE":"2","EXLEVEL":"15","PROMOTEDTYPE":"260","MEMBERID":"78912496","SHOPTYPE":"2","EXLEVEL&
阅读全文
摘要:比如:class="g">topic.csdn.net/u/20091018/11/ef331a56-93f ... 2011-3-28 </span> - <a其中以class="g">开头 ;</span> - <a结尾如何获取中间的字符串:topic.csdn.net/u/20091018/11/ef331a56-93f ... 2011-3-28 string str = "class=&
阅读全文
摘要:如题。现有代码如下。只能截取 http://www.baidu.com的 www.baidu.com当域名为https://www.baidu.com 或者为 http://www.baidu.com:8080 时 则无法正确读取。。求高手给去能截取这样格式的代码 Thanks! string p = @"http://[^\.]*\.(?<domain>[^\.]*)"; Regex reg = new Regex(p, RegexOptions.IgnoreCase); Match m = reg.Match(HostUrl); ...
阅读全文
摘要:using System;using System.Text.RegularExpressions;namespace SubStringDemo{ class Program { static void Main(string[] args) { string source = "123412355123559912323399"; string destString = "123"; Console.WriteLine("SubString count:" + SubString(so...
阅读全文