<a href="http://www.pc-boy.com" class="a1">阿呆在线</a>
在C#中 我要取这串字符中的"http://www.pc-boy.com" 和阿呆在线 保存到数组中
另外要是有一个特证就是<a></a>中要有class="a1" 才取<a(.+?)href=[\"\']?(.+?)[\"\'\s>]+(.+?)[>](.+?)<\/a>
这个只能取所有的:<A></A>
在C#中 我要取这串字符中的"http://www.pc-boy.com" 和阿呆在线 保存到数组中
另外要是有一个特证就是<a></a>中要有class="a1" 才取<a(.+?)href=[\"\']?(.+?)[\"\'\s>]+(.+?)[>](.+?)<\/a>
这个只能取所有的:<A></A>
using System.Collections;
using System.Text.RegularExpressions;public class MyClass
{
public static void Main()
{
String input = "<a href=\"http://www.pc-boy.com\" class=\"a1\">阿呆在线</a>";
String pattern = "<a\\s+href\\s*=\\s*[\"']{0,1}(?<1>[^\"']*)[\"']{0,1}\\s+class\\s*=\\s*[\"']{0,1}a1[\"']{0,1}[^>]*>(?<2>[^</]*)</a>";
Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
Console.WriteLine("Result : \n{0}", r.Replace(input, "${1}\n${2}"));
Console.ReadLine();
}
}