开发者

Regular expression for a list of numbers without other characters

I need a regular expression for a list of numbers in a text box with carriage returns and line feeds, but no other characters.

e.g.

1234 
5678 
5874 
3478

I have this:

Regex(@"\d\r\n${0,}?");

... but it is accepting commas when I paste them into my text box:

e.g.

1234,
5678
5开发者_开发问答874,
3478

Can someone please tell me what I'm doing wrong?

Thanks


Quite a lot is wrong with your Regex =)

  • \d matches one number, not several
  • $ matches the end of the line, {0,} means, that the symbol before it may appear zero or more times. But zero or more end of lines are not very useful.
  • The ? is superfluous, I think.
  • You are missing the start of line character.

Your regex matches the example you have given, because it matches the "8" in the second line.

Use this regex instead:

"^(\d*\r\n)*$"


Try * instead of {0,} - they mean the same thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜