Timeline for How to extract a floating number from a string
Current License: CC BY-SA 4.0
21 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 15, 2024 at 8:10 | comment | added | beta green |
(?:[+-]*\d+[\.]*\d*) should work.
|
|
| Jul 8, 2024 at 16:26 | comment | added | Sadidul Islam |
\\d+.\\d+ if get SyntaxWarning: invalid escape sequence '\d'
|
|
| Dec 7, 2022 at 12:04 | history | edited | miku | CC BY-SA 4.0 |
deleted 3 characters in body
|
| Mar 25, 2022 at 18:56 | history | edited | srm | CC BY-SA 4.0 |
Modified example to show that this works even if there aren't spaces delimiting the number.
|
| Mar 18, 2022 at 14:38 | comment | added | CechMS | Thank you ! Do you have any idea to include number like this : 1,075.01 please ? | |
| Jan 15, 2022 at 20:02 | history | edited | Wiktor Stribiżew | CC BY-SA 4.0 |
fixed the second regex, people use it and start asking questions why the minus/plus sign is not returned with int numbers
|
| Jun 23, 2018 at 16:47 | comment | added | Velizar VESSELINOV | missign thousand separators, scientific expression, better answer available on the page | |
| Dec 17, 2017 at 21:11 | comment | added | woryzower |
that will miss negative integers "-35 um". Should alternation have [-+]? at the beginning: #"[-+]?\d*\.\d+|[-+]?\d+"
|
|
| Oct 8, 2017 at 17:50 | review | Suggested edits | |||
| Oct 8, 2017 at 21:07 | |||||
| Sep 19, 2017 at 16:45 | comment | added | dashesy |
@JuanPablo looks fine but r"[-+]?\d*\.?\d+" is a little more concise and will not accept 0..4
|
|
| May 1, 2016 at 16:48 | comment | added | Eli Korvigo |
@psun extracts + or - if present.
|
|
| Apr 29, 2016 at 17:53 | comment | added | psun |
what does [-+]? in the code do?
|
|
| Jan 14, 2016 at 15:39 | comment | added | maazza | how would you handle something like "level:12,25;" ? | |
| Dec 6, 2015 at 1:51 | history | edited | miku | CC BY-SA 3.0 |
added 1 character in body
|
| Aug 25, 2014 at 22:27 | comment | added | JuanPablo |
re.findall(r"[-+]?\d*\.*\d+", "Current Level: -13.2 db or 14.2 or 3") ['-13.2', '14.2', '3']
|
|
| Jan 16, 2011 at 2:37 | vote | accept | Ben Keating | ||
| Jan 16, 2011 at 2:36 | history | edited | miku | CC BY-SA 2.5 |
added 362 characters in body; added 42 characters in body; added 3 characters in body; added 153 characters in body
|
| Jan 16, 2011 at 2:27 | history | edited | miku | CC BY-SA 2.5 |
deleted 2 characters in body; added 36 characters in body
|
| Jan 16, 2011 at 2:22 | history | edited | miku | CC BY-SA 2.5 |
added 8 characters in body; added 116 characters in body; deleted 9 characters in body
|
| Jan 16, 2011 at 2:17 | comment | added | Ben Keating | it is not always a decimal number. | |
| Jan 16, 2011 at 2:16 | history | answered | miku | CC BY-SA 2.5 |