The value *must* contain at least one number, but *may* also contain periods and hyphens.My first reaction is: /\d/ (4 chars). This matches any string that contains at least one number. The string may also contain periods and hyphens. And any other character for that matter - your requirement doesn't say those characters are forbidden.
But I guess the hidden requirement is that it doesn't contain anything else. You can test for that with two regexes: /\d/&&!/[^-.\d]/ (16 chars). Or, if you want to do it in one regex: /^[-.]*\d[-\d.]*$/ (18 chars).
Abigail
In reply to Re: Golf this reg ex
by Abigail-II
in thread Golf this reg ex
by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |