1.取出网页中的Title属性
Match TitleMatch = Regex.Match(fileContents, "<title>([^<]*)</title>", RegexOptions.IgnoreCase | RegexOptions.Multiline );
filetitle = TitleMatch.Groups[1].Value;
注意红色的1, Regex.Match方法得到的Groups的索引是从1开始的,而不是从0开始的
2. 取出网页头部的"Content"属性
Match DescriptionMatch = Regex.Match( fileContents, "<META NAME=/"DESCRIPTION/" CONTENT=/"([^<]*)/">", RegexOptions.IgnoreCase | RegexOptions.Multiline );
filedesc = DescriptionMatch.Groups[1].Value;
3、判断字符串是否为数字
public static bool ISNumber(string p_strInput)
{
if (p_strInput == null)
{
return false;
}
return Regex.IsMatch(p_strInput,@"^/d+$",RegexOptions.Singleline);
}
4、根据一个url路径获得这个文件的后缀名
private static string GetExtensionForUrl(string strUrl)
{
Match match1 = Regex.Match(strUrl, @"/.(/w+)(/?.*)?$", RegexOptions.IgnoreCase);
if (match1.Success)
{
return match1.Groups[1].Value;
}
else
{
return String.Empty;
}
}
4、统计参数里面的英文字符,看好是英文字符啊,包括大小写
并且排序后输出,假如参数是 ddcccbAa 输出格式为: a(1)b(1)c(3)d(2)A(1)
public String countSubString(String str) {
//排序先
str = sort(str);
System.out.println(str);
String regExp = "([a-zA-Z])//1*";
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(str);
//System.out.println(m.group());
StringBuffer sb = new StringBuffer();
int counter=0;
while (m.find()) {
System.out.println("counter:"+(++counter));
String temp = m.group();
System.out.println(m.groupCount());
System.out.println(temp);
sb.append(
temp.charAt(0)).
append('(').
append(temp.length()).
append(')');
}
return sb.toString();
}