heroku/databasedotcom — pull request #120 by jearsh (2013-03-14 06:47:30+00:00)
Title: Removed unnecessary aspects of regex

Super long explanation for a removing 3 characters from a regex. Sorry, just trying to be thorough. Please don't judge future pull requests based on this one.

tl;dr => There are two 0-9 in a character class. There only needs to be one.

[ Longer Explanation ]

A character class represents a single character, all of the characters in it only need to be listed once.

Original RegEx: [^-0-9.0-9]
Reads in english as: "Anything that is not a hyphen, or a number, or a dot, or a number"
See: "or a number" is there 2x, when it only needs to be there 1x.

It seems the confusion is the 0-9 range after the '.'. Because you already have '0-9' before the dot, you don't need it again after the dot.

I mentioned position in character classes, because the original regex may have meant to say:

"Anything that is not a hypen, followed by numbers before a dot, followed by a dot, followed by numbers after a dot".

The prepositions (before/after a dot) are not how character classes work.
If this is how the regex was intended to be read, then the understanding of how regular expressions/character classes work was inaccurate at the time it was written.

Position only matters in a character class for 2 cases:
1. When you want to match a literal hyphen (-).
(i.e. not using it for a range: 0-9)
2. When you want to match anything _not_ in the class. (Using ^ to invert the class)
(e.g. [^abc] matches anything not an a, b, or c)

Both of these cases are relevant and accurate in your character class. They are not the problem.