Tom Christiansen gave an awesome answer to the question of how to match a number with a regular expression. He begins by clarifying what the reader means by “number”, then gives answers for each.

- Is
`−0`

a number? - How do you feel about
`√−1`

? - Is
`⅝`

or`⅔`

a number? - Is
`186,282.42±0.02`

miles/second one number — or is it two or three of them? - Is
`6.02e23`

a number? - Is
`3.141_592_653_589`

a number? How about`π`

, or`ℯ`

? And`−2π⁻³ ͥ`

? - How many numbers in
`0.083̄`

? - How many numbers in
`128.0.0.1`

? - What number does
`⚄`

hold? How about`⚂⚃`

? - Does
`10,5 mm`

have one number in it — or does it have two? - Is
`∛8³`

a number — or is it three of them? - What number does
`ↀↀⅮⅭⅭⅬⅫ AUC`

represent, 2762 or 2009? - Are
`४५६७`

and`৭৮৯৮`

numbers? - What about
`0377`

,`0xDEADBEEF`

, and`0b111101101`

? - Is
`Inf`

a number? Is`NaN`

? - Is
`④②`

a number? What about`⓰`

? - How do you feel about
`㊅`

? - What do
`ℵ₀`

and`ℵ₁`

have to do with numbers? Or`ℝ`

,`ℚ`

, and`ℂ`

?

See his full response here. Thanks to Bill the Lizard for pointing this out.

For daily tips on regular expressions, follow @RegexTip on Twitter.

Is 5% a number?

(I think so if ⅝ is, 5% is just shorthand for 5/100.)

5% is shorthand for 5/100, but it takes different regular expressions to match “5%” and “5/100”.

Also: is “two” a number? is “half” a number? is “none” a number?

That said, the stack overflow question Tom was responding to was pretty clear: It did not even use the word “number” in the question — only in the title. The title also specified “only digits and commas”. The examples included a minus sign which suggests that ЯegDwight (the person asking the question) considered the minus sign to be a digit, and the examples showed that precise spacing of the commas was not important.

So simplicity suggests that most of the cases proposed by Tom Christiansen were not based on this question.