C#html抽取所有文本内容的正则表达式
- 时间:2015年04月02日 15:40:50 来源:魔法猪系统重装大师官网 人气:11217
只抽取HTML中 所有之间的文本的正则表达式:(?is)
测试代码:
public static void Main(string[] args)
{
string text="![]()
string regex=@"(?is)
GetListByHtml(text, regex);
Console.ReadKey();
}
public static void GetListByHtml(string text,string pat)
{
System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(pat, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Match m = r.Match(text);
//int matchCount = 0;
while (m.Success)
{
Console.WriteLine(m.Value);
m = m.NextMatch();
}
}
这是抽取herf的例子 string regexs = "href=[\\\"\\\'](http:\\/\\/|\\.\\/|\\/)?\\w+(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*(\\/|\\?\\w*=\\w*(&\\w*=\\w*)*)?[\\\"\\\']";
C#html,抽取,所有,文本,内容,的,正则,表达式,只,
]*>(?>
]*>(?
测试代码:
public static void Main(string[] args)
{
string text="
sdfasdfsa
sxcvxc23424
";string regex=@"(?is)
]*>(?>
]*>(?
GetListByHtml(text, regex);
Console.ReadKey();
}
public static void GetListByHtml(string text,string pat)
{
System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(pat, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Match m = r.Match(text);
//int matchCount = 0;
while (m.Success)
{
Console.WriteLine(m.Value);
m = m.NextMatch();
}
}
这是抽取herf的例子 string regexs = "href=[\\\"\\\'](http:\\/\\/|\\.\\/|\\/)?\\w+(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*(\\/|\\?\\w*=\\w*(&\\w*=\\w*)*)?[\\\"\\\']";
上一篇:批量命令行替你解决嵌入式开发中重复copy映像的烦恼
下一篇:几道C语言习题求解





