You're viewing a comment by Zefram and its responses.

Zefram Permalink
November 10, 2011, 12:51

/^\d+$/ is faulty. Firstly, /$/ doesn't just match end-of-string, it will also match at a newline followed by end-of-string. So the regexp matches "1\n" as well as "1". Many of your regexps suffer this flaw.

Secondly, /\d/ is not a synonym for /[0-9]/. It also matches many Unicode digit-like characters. So your regexp matches "\x{666}", which probably doesn't look sufficiently like a number for whatever you were planning to do with it. Many of your regexps have this flaw too.

So /^\d+$/ should be /\A[0-9]+\z/, and many of the other regexps should be amended similarly.

Comment Responses

November 10, 2011, 15:01


Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "disk_277": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.