Timeline for answer to Using isdigit for floats? by Peter C
Current License: CC BY-SA 2.5
Post Revisions
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 18, 2013 at 21:21 | comment | added | Peter C | @mrooney: I wrote this like 3 years ago. I definitely think dan04's answer is much better now. However, simply changing the regex to /^\d+(\.\d+)?$/ should be fine. I don't think matching .1 is much of a necessity, and he doesn't want to match negative numbers. | |
| Sep 18, 2013 at 20:03 | comment | added | mrooney | Unfortunately this isn't a good regex for floats and so doesn't really answer the question. For example it doesn't match ".1" but DOES match "5abc". There are also negative values and other notations, so it is probably ideal to use dan04's answer, turning it into a function if you need to use it in a list comprehension or argument. | |
| Nov 10, 2010 at 22:31 | vote | accept | Peter Nolan | ||
| Nov 10, 2010 at 1:16 | comment | added | Peter C | @Steven Rumbalski: Yeah, dan04's solution seems more Pythonic, thought mine may actually be less code. | |
| Nov 9, 2010 at 20:43 | comment | added | Steven Rumbalski | Those regular expressions are so damn flexible! Still, dan04's solution feels much more pythonic. Here I define pythonic as "between two solutions of equivalent complexity, prefer the one that doesn't use regular expressions." That still leaves many applications for regular expressions. | |
| Nov 9, 2010 at 20:33 | history | answered | Peter C | CC BY-SA 2.5 |