in reply to Golf this reg ex
Next, [0-9] is the same as \d.
Third, the non-capturing parens are not helping you.
Boil that down and you get:
print "$1\n" if $number =~ m/ ^( [\d.-]* \d [\d.-]* )$ /x;
Oh, forgot to mention; the /x modifier helps to keep things clean and tidy looking.
If you really want it golfed, how about this:
$number =~ /^([\d.-]*\d[\d.-]*)$/ and print "$1\n";
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Golf this reg ex
by Abigail-II (Bishop) on Apr 16, 2004 at 09:59 UTC |