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
−0a number? - How do you feel about
√−1? - Is
⅝or⅔a number? - Is
186,282.42±0.02miles/second one number — or is it two or three of them? - Is
6.02e23a number? - Is
3.141_592_653_589a 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 mmhave one number in it — or does it have two? - Is
∛8³a number — or is it three of them? - What number does
ↀↀⅮⅭⅭⅬⅫ AUCrepresent, 2762 or 2009? - Are
४५६७and৭৮৯৮numbers? - What about
0377,0xDEADBEEF, and0b111101101? - Is
Infa number? IsNaN? - 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.
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.