请问,这个正则表达式,哪里错了?

ssdrce2f12 2012-04-20 10:19:35
static void Main(string[] args)
{
string pattern = @"\b+";
Regex rgx = new Regex(pattern);
string sentence = "dfgs4aer25#@";
foreach (Match match in rgx.Matches(sentence)) //foreach遍历所有匹配项
{
Console.WriteLine(match.Value);
}
Console.ReadKey();
}

这个正则表达式,是搜索字符串"dfgs4aer25#@"中的所有数字,应该是4和25,为什么最后没有输出结果呢?哪里出错了?
...全文
52 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
EnForGrass 2012-04-20
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

引用楼主 的回复:
static void Main(string[] args)
{
string pattern = @"\b+";
Regex rgx = new Regex(pattern);
string sentence = "dfgs4aer25#@";
foreach (Match……

你要匹配数字怎么会成\b+呢?
匹配数字用\d或者[0-9]啊
[/Quote]
你要匹配dfgs4aer25#@中的数字

可用\d+或者[0-9]+或者[^\D]+也行
EnForGrass 2012-04-20
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
static void Main(string[] args)
{
string pattern = @"\b+";
Regex rgx = new Regex(pattern);
string sentence = "dfgs4aer25#@";
foreach (Match……
[/Quote]
你要匹配数字怎么会成\b+呢?
匹配数字用\d或者[0-9]啊
test2050 2012-04-20
  • 打赏
  • 举报
回复
1楼正解。\d是数字
anzhiqiang_touzi 2012-04-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
\d+
[/Quote]
threenewbee 2012-04-20
  • 打赏
  • 举报
回复
\d+

110,534

社区成员

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

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

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