求一取值正则表达式

空白是我 2009-07-29 10:55:55
格式:
6位数字=值;

123456=15;
225845=23;
666666=55;

我想根据前面六位数字取得后面的值,不带分号
这样的正则表达式该如何写呀
...全文
113 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
rainsome 2009-07-29
  • 打赏
  • 举报
回复

//楼主,可是要的这样的效果
//(仅供参考)
private void fun1()
{
string str = @"123456=15;
225845=23;
666666=55; ";




string strTest = "123456";
Response.Write(String.Format("Filter:{0};Result:{1}.<br />", strTest, GetTheNumber(str, strTest)));

Int32 intTest = 666666;
Response.Write(String.Format("Filter:{0};Result:{1}.<br />", intTest, GetTheNumber(str, intTest)));

Response.Write(String.Format("Source String:{0}.<br />", str));


}

private Int32? GetTheNumber(String src,Object objFilter)
{
if (!Regex.IsMatch(objFilter.ToString(), @"^\d{6}$")) return null;

Regex objRegex = new Regex(string.Format(@"(?m)(?<={0}=)\d+?(?=;)", objFilter));

Match m = objRegex.Match(src);

if (m.Success)
{
Int32 _return;
bool _isParse =Int32.TryParse(m.Value,out _return);
if (_isParse)
{
return _return;
}
else
{
return null;
}
}
else
{
return null;
}
}

/*
//Asp中显示结果
Filter:123456;Result:15.
Filter:666666;Result:55.
Source String:123456=15; 225845=23; 666666=55; .
*/
lovvver 2009-07-29
  • 打赏
  • 举报
回复
string numberString = "123456=15; ";
string pattern = "\\d{6}=(?<Info>.*);";
MatchCollection matchCollection = Regex.Matches(numberString, pattern);
if (matchCollection.Count == 0) MessageBox.Show("not mathced.");
else
{
string result = matchCollection[0].Groups["Info"].Value;
MessageBox.Show(result);
}
空白是我 2009-07-29
  • 打赏
  • 举报
回复
OK 给分
十八道胡同 2009-07-29
  • 打赏
  • 举报
回复
.Group["YourNum>"].value
空白是我 2009-07-29
  • 打赏
  • 举报
回复
是取后面的值
比如 123456 应该取到的值是15
而不是123456=15
十八道胡同 2009-07-29
  • 打赏
  • 举报
回复
"(\d){6}\=(?<YourNum>\d+);"
编程有钱人了 2009-07-29
  • 打赏
  • 举报
回复

(\d){6}\=(?<oo>\d+);

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧