///
///去掉
static voidTest2()
{//要匹配的字符串
string text = @"hello
alert(‘1‘);
regex
alert(‘2‘);
world";//正则表达式
string pattern = @"";//string result = Regex.Replace(text, pattern, "").Replace("\r\n","").Replace(" ","");
string result = Regex.Replace(text, pattern, "").Replace(" ", "");
Console.WriteLine(result);
}///
///获取
static voidTest3()
{//要匹配的字符串
string text = @"hello
alert(‘1‘);
regex
alert(‘2‘);
world";//正则表达式
string pattern = @"";
Regex r= newRegex(pattern, RegexOptions.IgnoreCase);//string result = Regex.Replace(text, pattern, "").Replace("\r\n","").Replace(" ","");
MatchCollection matchCollection =r.Matches(text);foreach (Match m inmatchCollection)
{//显示匹配开始处的索引值和匹配到的值
System.Console.WriteLine("Match=[" + m + "]");
CaptureCollection cc=m.Captures;foreach (Capture c incc)
{
Console.WriteLine("/tCapture=[" + c + "]");
}for (int i = 0; i < m.Groups.Count; i++)
{
Group group=m.Groups[i];
System.Console.WriteLine("/t/tGroups[{0}]=[{1}]", i, group);for (int j = 0; j < group.Captures.Count; j++)
{
Capture capture=group.Captures[j];
Console.WriteLine("/t/t/tCaptures[{0}]=[{1}]", j, capture);
}
}
}
}