using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions;namespace ConsoleApplication1 { class Test { static void Main() { string[] str = new string[] { @"http://www.abc.com/12345", @"http://www.abc.com/12345/", @"http://www.abc.com/123454" }; Regex re = new Regex(@"^http://www.abc.com/\d{5}/?$"); foreach (string s in str) { if (re.Match(s).Success) Console.WriteLine(re.Match(s).Value); } } } }
是项目规定吗?如果是这样,那就用正则吧 否则不用正则也完全可以 string[] s = new string[] { "http://www.abc.com/12345/", "http://www.abc.com/12345" }; foreach (string p in s) { if (p.EndsWith("/")) { Console.WriteLine(p); } }
if (s.EndsWith("/"))//是否有/符号
{
}
else
{
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;namespace ConsoleApplication1
{
class Test
{
static void Main()
{
string[] str = new string[] { @"http://www.abc.com/12345", @"http://www.abc.com/12345/", @"http://www.abc.com/123454" };
Regex re = new Regex(@"^http://www.abc.com/\d{5}/?$");
foreach (string s in str)
{
if (re.Match(s).Success)
Console.WriteLine(re.Match(s).Value); } }
}
}
否则不用正则也完全可以 string[] s = new string[] { "http://www.abc.com/12345/", "http://www.abc.com/12345" };
foreach (string p in s)
{
if (p.EndsWith("/"))
{
Console.WriteLine(p);
}
}
<LookFor>~/(\d{5})/</LookFor>
<SendTo>~/index.aspx?page=$1</SendTo>
</RewriterRule>