问一个正则表达式,100分 IIS://localhost/w3svc/1/root/1/2/3我要得到w3svc与root中间的数字,怎么写正则表达式,这个数字可能是任何数字,只要这个数字。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参考http://bingning.net/VB/SOURCE/string/regexmatch.html这里看看 declare @x nvarchar(100),@l int, @l2 int,@num varchar(200)set @x = 'IIS://localhost/w3svc/1/root/1/2/3'set @l = Charindex('w3svc/',@x)set @l2 = Charindex('/root/',@x)set @num = substring(@x,@l+6,@l2-@l-6)print(@num)这个是我用sql写的思路你看看一般找出数字 前头的位置,然后找出数字后头的位置,想减得出数字长度,然后截取字段。正则也没有办法获得你想要的。只能做个判断 string output=string.Empty;Regex reg=new Regex(@"iis://localhost/w3svc/(\d+)/root",RegexOption.IgnoreCase);if(reg.IsMatch(XXXX)){ output=reg.Matches(XXXX)[1];} @"(?i)(?<=IIS://localhost/w3svc/)\d+" string test = "IIS://localhost/w3svc/1/root/1/2/3 ";Console.WriteLine("the string is:{0}",test);Match m = Regex.Match(test, @"(?<=w3svc/).+(?=/root.+)", RegexOptions.IgnoreCase);Console.WriteLine("match is:{0}",m.Value); /*the string is:IIS://localhost/w3svc/1/root/1/2/3match is:1请按任意键继续. . .*/ string str = "IIS://localhost/w3svc/1/root/1/2/3";string result = Regex.Match(str,@"/w3svc/(\d+)/root/").Groups[1].Value; 视频文件变成一张张的图片 在WINFORM中,如何对datagridview 求和 请教判断字符串是否符合要求的问题 treeView数据问题 字符串截取问题 新上传了一批【免分】下载资源 winform中datagrid如何设置一列的颜色!谢谢大家,着急!!! 请哪位大侠有QQ的源代码啊 有没有c#SOCKET编程的电子书,深一点的 这个 C# 正则表达式怎么写呢? ODP.NET的问题 判断在线、离线的问题
declare @x nvarchar(100),@l int, @l2 int,@num varchar(200)
set @x = 'IIS://localhost/w3svc/1/root/1/2/3'
set @l = Charindex('w3svc/',@x)
set @l2 = Charindex('/root/',@x)
set @num = substring(@x,@l+6,@l2-@l-6)
print(@num)
这个是我用sql写的思路
你看看
一般找出数字 前头的位置,然后找出数字后头的位置,想减得出数字长度,
然后截取字段。
正则也没有办法获得你想要的。只能做个判断
Regex reg=new Regex(@"iis://localhost/w3svc/(\d+)/root",RegexOption.IgnoreCase);
if(reg.IsMatch(XXXX))
{
output=reg.Matches(XXXX)[1];
}
Console.WriteLine("the string is:{0}",test);Match m = Regex.Match(test, @"(?<=w3svc/).+(?=/root.+)", RegexOptions.IgnoreCase);
Console.WriteLine("match is:{0}",m.Value);
/*
the string is:IIS://localhost/w3svc/1/root/1/2/3
match is:1
请按任意键继续. . .
*/
string str = "IIS://localhost/w3svc/1/root/1/2/3";
string result = Regex.Match(str,@"/w3svc/(\d+)/root/").Groups[1].Value;