views:

159

answers:

4

What does the regular expression "\d{1,6}" (used in an ASP.NET MVC route as parameter constraint) check for/allow?

+4  A: 

a number with 1-6 digits

Devin Ceartas
"100,000" is a number with 6 digits.
Bill the Lizard
So is 1.623e-12 but that's *also* being picky :-)
paxdiablo
Sorry, I don't mean to be picky, but regular expressions are very picky about what they will match. :)
Bill the Lizard
No, you *should* be picky. Engineering is, after all, meant to be an exact science. Otherwise I would have majored in English Lit.
paxdiablo
+16  A: 

That will match 1-6 consecutive occurrences of any of the digits 0-9 (not necessarily the same digit).

Bill the Lizard
acc. even though later because you clarified that it has to be consecutive.
Alex
+1 for being meticulously accurate.
paxdiablo
+4  A: 

\d is the class for digits the {1,6} means one to six element(s) of that class

if you want some reference you can consult this website probably not the best but kind of nice summary.

RageZ
+1  A: 

\d means a single decimal character. 0~9.

{minimum-length, maximum-length} means a precede expression (\d in this case) will be followed repeatedly.

As a result, your expression \d{1,6} would match any of them.

0 12 874 4757 48727 557473

xrath