I’m not sure if this is the appropriate place for this, but it’s short (and I found it in a JS file):
/^[\\-\\d\\.]+$/
What does this mean? “\d” is for digits, but “\.” matches all digits and then some, right? Or is “\.” for a literal period? And what is “\-”? Does that mean "look for the literal ‘-’ " or is it a special symbol?
You don’t need to escape the dash if it’s the first character in the character class (the square brackets), otherwise you do (because it indicates a range of characters). And you don’t need to escape the dot in a character class either, only outside it. So you can reduce it to:
[-5] could indicate the range [0-5] with the 0 omitted, only it wasn’t implemented this way. (might be in the future and/or in other languages though!)
That’s a bit of a stretch - I don’t think -5 would ever be interpreted as “0-5”; more like minus five or, as it (sensibly) is at the moment, “dash or five”.
As long are there people that find it interesting to program with only spaces, tabs, and line ends, there will also be people who find it interesting to treat [-5] as [0-5] …
Ah, whitespace! As awesome as LOLCODE and Brainf*ck : )
Javascript uses Perl Compatible Regular Expressions, where the rule is that a - starting (or sometimes, ending) a character class are not considered to be part of a range (ranges are not implied without a start and a stop inside ). However, you’re not going to hurt anything by escaping it, and maybe is safer for anyone going between languages who maybe use other types of regexes.
It’s not very far off-topic, until you start talking about your favourite sub-species of lemur or what method you use to put your socks on in the morning.
Yeah, the basic stuff (and most of the advanced stuff) is very portable across languages.
until you start talking about your favourite sub-species of lemur
Ringtails aren’t a subspecies but they’re my favourites because of the awesome tails and the way they tip their heads back while eating fruits so as not to spill the juices[/ot]