Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我一直在用 C# 开发我自己的简单维基百科解析器。到目前为止,由于这个问题,我还没有走得太远。
我提取字符串{e|24},但它可以包含任何数字。我想做的只是从这个字符串中提取数字。
{e|24}
这是我目前使用的代码:
Match num = Regex.Match(exp.Value, "[0-9]*"); Console.WriteLine(num.Value);
然而num.Value是空白。
num.Value
有人可以解释为什么这不起作用以及我该如何解决?
您可能希望使用 [0-9]+ 来确保至少有一个数字。[0-9]* 允许匹配 0 次或更多,从而得到空白
我的建议,使正则表达式:\d+
\d+
作品。更简单。更短,不使用组或范围。