正则表达式匹配问题

ljasondon 2011-02-18 12:41:37
str="sasa:121sajkj,12asa";
str2="sasa:12:12:12:12sas,121sa";
MatchCollection m = Regex.Matches(str, "[0-9]", RegexOptions.IgnoreCase);
这样写会取出所有的数字
我想取出冒号后面的数字,应该怎么写
strNum=121;
strNum2=12121212;
...全文
57 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
挨踢直男 2011-02-18
  • 打赏
  • 举报
回复
@"(?<=\:)[0-9]+"
sprc_lcl 2011-02-18
  • 打赏
  • 举报
回复
str2="sasa:12:12:12:12sas,121sa";
strNum2 = Regex.Match(str2, "(:\d+)+").Value.Replace(":","");
wuyq11 2011-02-18
  • 打赏
  • 举报
回复
string str = "sasa:121sajkj,12asa";
foreach (Match m in Regex.Matches(str, @"(?s)[^>]*:(?<title>\d+)[^>]*,"))
{
Console.WriteLine(m.Groups["title"].Value);
}
ljasondon 2011-02-18
  • 打赏
  • 举报
回复
不行,截取不到

110,547

社区成员

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

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

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