Regex reg = new Regex("-"); // Split on hyphens.
string[] s = reg.Split("first-second-third");
for (int i = 0; i < s.Length; i++)
{
Response.Write(s[i] + "<br>");
}
string text = "1A 2B 3C 4D 5E 6F 7G 8H 9I 10J 11Q 12J 13K 14L 15M 16N ffee80 #800080";
string pattern = @"((\d+)([a-z]))+";
Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matchCollection = r.Matches(text);
foreach (Match m in matchCollection)
{
Response.Write(m.ToString()+"<br>");
}
//匹配正确返回真(true) 否则返回假(false)
//Regex.IsMatch("字符串","表达式",RegexOptions.IgnoreCase);
//Response.Write(r.Match(text)); 只匹配第一个
MatchCollection mc;
r = new Regex("match");
mc = r.Matches("matchcollectionregexmatchs");
for (int i = 0; i < mc.Count; i++)
{
Response.Write(mc[i].Value + " POS:" + mc[i].Index.ToString() + "<br>");
}
string[] s = reg.Split("first-second-third");
for (int i = 0; i < s.Length; i++)
{
Response.Write(s[i] + "<br>");
}
string text = "1A 2B 3C 4D 5E 6F 7G 8H 9I 10J 11Q 12J 13K 14L 15M 16N ffee80 #800080";
string pattern = @"((\d+)([a-z]))+";
Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matchCollection = r.Matches(text);
foreach (Match m in matchCollection)
{
Response.Write(m.ToString()+"<br>");
}
//匹配正确返回真(true) 否则返回假(false)
//Regex.IsMatch("字符串","表达式",RegexOptions.IgnoreCase);
//Response.Write(r.Match(text)); 只匹配第一个
MatchCollection mc;
r = new Regex("match");
mc = r.Matches("matchcollectionregexmatchs");
for (int i = 0; i < mc.Count; i++)
{
Response.Write(mc[i].Value + " POS:" + mc[i].Index.ToString() + "<br>");
}