111,126
社区成员
发帖
与我相关
我的任务
分享
Regex re = new Regex("(?is)(?<=<tr[^>]*>\\s*<td[^>]*>\\s*<a.*?href=\")[^\"]+(?=\">)");
Match m = re.Match(input);
while (m.Success)
{
Console.WriteLine(m.Value);
m = m.NextMatch();
}// 我是这样用的 是可以的
string[] fileUrl = Exstring.GetInsideStr("代码文件","<td class=\"odd\"> <a href=\"","\">");
/// <summary>
/// 扩展字符串处理
/// </summary>
public class ExString
{
/// <summary>
/// 获取该文字出现的次数
/// </summary>
/// <param name="str">需要查找的主体文档</param>
/// <param name="pointStr">关键文字</param>
/// <returns>次数</returns>
public static int GetStrTime(string str,string pointStr)
{
int result = -1;//统计总数
int nowpoint = 0;//计算当前位置
while (nowpoint != -1)
{
result++;
if (nowpoint == 0)
nowpoint = str.IndexOf(pointStr);
else
nowpoint = str.IndexOf(pointStr, nowpoint + 1);
}
return result;
}
#region 获取某两个字符串里面的所有字符串
/// <summary>
/// 获取某两个字符串里面的所有字符串
/// 前后标志字符不可一样
/// </summary>
/// <param name="str">主体文档</param>
/// <param name="strA">前面的字符串</param>
/// <param name="strB">后面的字符串</param>
/// <returns>夹在中间的字符串集</returns>
public static string[] GetInsideStr(string str, string strA, string strB)
{
int A = 0, B = 0;
int AL = strA.Length;
int BL = strB.Length;
System.Collections.ArrayList forsave = new System.Collections.ArrayList();
while (true)
{
if (B == 0)
A = str.IndexOf(strA);
else
A = str.IndexOf(strA, B + BL);//从上个B结尾处开始找A
if (A != -1)//有可能A为-1
{
B = str.IndexOf(strB, A + AL);//从上面的A后面开始找B
if (B != -1)
{
A = str.LastIndexOf(strA, B);//从B往前找A 位置确定AB间
forsave.Add(str.Substring(A + AL, B - A - AL));
}
else
break;
}
else
break;
}
string[] result = (string[])forsave.ToArray(typeof(string));
return result;
}
/// <summary>
/// 获取某两个字符串里面的所有字符串
/// 前后标志字符不可一样
/// </summary>
/// <param name="str">主体文档</param>
/// <param name="strA">前面的字符串</param>
/// <param name="offsetA">前面的偏移位置数(往右)</param>
/// <param name="strB">后面的字符串</param>
/// <param name="offsetB">后面的偏移位置数(往右)</param>
/// <returns>夹在中间的字符串集</returns>
public static string[] GetInsideStr(string str, string strA, int offsetA, string strB, int offsetB)
{
int A = 0, B = 0;
int AL = strA.Length + offsetA;
int BL = strB.Length + offsetB;
System.Collections.ArrayList forsave = new System.Collections.ArrayList();
while (true)
{
if (B == 0)
A = str.IndexOf(strA);
else
A = str.IndexOf(strA, B + BL);//从上个B结尾处开始找A
if (A != -1)//有可能A为-1
{
B = str.IndexOf(strB, A + AL);//从上面的A后面开始找B
if (B != -1)
{
A = str.LastIndexOf(strA, B);//从B往前找A 位置确定AB间
forsave.Add(str.Substring(A + AL, B - A - AL));
}
else
break;
}
else
break;
}
string[] result = (string[])forsave.ToArray(typeof(string));
return result;
}
/// <summary>
/// 获取某两个字符串里面的所有字符串
/// 前后标志字符不可一样
/// </summary>
/// <param name="getindex">获取第几个匹配的字符(无则返回null)</param>
/// <param name="str">主体文档</param>
/// <param name="strA">前面的字符串</param>
/// <param name="strB">后面的字符串</param>
/// <returns>夹在中间的字符串集</returns>
public static string GetInsideStr(int getindex,string str, string strA, string strB)
{
int A = 0, B = 0;
int AL = strA.Length;
int BL = strB.Length;
System.Collections.ArrayList forsave = new System.Collections.ArrayList();
while (true)
{
if (B == 0)
A = str.IndexOf(strA);
else
A = str.IndexOf(strA, B + BL);//从上个B结尾处开始找A
if (A != -1)//有可能A为-1
{
B = str.IndexOf(strB, A + AL);//从上面的A后面开始找B
if (B != -1)
{
A = str.LastIndexOf(strA, B);//从B往前找A 位置确定AB间
forsave.Add(str.Substring(A + AL, B - A - AL));
}
else
break;
}
else
break;
}
string[] result = (string[])forsave.ToArray(typeof(string));
try
{
return result[getindex - 1];
}
catch
{
return null;
}
}
/// <summary>
/// 获取某两个字符串里面的所有字符串
/// 前后标志字符不可一样
/// </summary>
/// <param name="str">主体文档</param>
/// <param name="getindex">获取第几个匹配的字符(无则返回null)</param>
/// <param name="strA">前面的字符串</param>
/// <param name="offsetA">前面的偏移位置数(往右)</param>
/// <param name="strB">后面的字符串</param>
/// <param name="offsetB">后面的偏移位置数(往右)</param>
/// <returns>夹在中间的字符串集</returns>
public static string GetInsideStr(int getindex, string str, string strA
, int offsetA, string strB, int offsetB)
{
int A = 0, B = 0;
int AL = strA.Length + offsetA;
int BL = strB.Length + offsetB;
System.Collections.ArrayList forsave = new System.Collections.ArrayList();
while (true)
{
if (B == 0)
A = str.IndexOf(strA);
else
A = str.IndexOf(strA, B + BL);//从上个B结尾处开始找A
if (A != -1)//有可能A为-1
{
B = str.IndexOf(strB, A + AL);//从上面的A后面开始找B
if (B != -1)
{
A = str.LastIndexOf(strA, B);//从B往前找A 位置确定AB间
forsave.Add(str.Substring(A + AL, B - A - AL));
}
else
break;
}
else
break;
}
string[] result = (string[])forsave.ToArray(typeof(string));
try
{
return result[getindex - 1];
}
catch
{
return null;
}
}
#endregion
}
"(?is)(?<=<tr[^>]*>\\s*<td[^>]*>\\s*<a.*?href=\")[^\"]+(?=\">)"
// 应该有九个吧
"(?<=<tr[^>]*>\\s*<td[^>]*>\\s*<a.*?href=\")[^\"]+(?=\">)" // 应该有九个吧