I am parsing a file with Python which has words and numbers. I am only interested in numbers, i.e. only characters 0 to 9, dot(.) and comma (,). I am interested in keeping both dot and comma because some files are written in the American style numbers, i.e. 3.14159 while some others are in European (German) style, i.e. 3,14159.
I would like to have a simple solution, i.e. without any for loops, without generators, yields or complicated functions. Using regular-expression (re) library is completely fine but it would be great if you can explain what the re.func() is doing so that we understand how to call it differently later if needed.
My input is a string of mixed up numbers and characters. Two consecutive numbers are always separated by one or more characters other than the decimal characters. The desired output should be a list of strings, i.e. one string for each extracted number. Following is an example, where there are three numbers to be separated, i.e. 3.14, 3,14 and 85.2
Example input:
This Is3.14ATes t3,14 85.2
Desired Output:
['3.14', '3,14', '85.2']
My apologies if there is already some other post here which addresses the exact same problem. Though I have searched a lot for a similar questions here but the closest I could find was this: Regular expression numbers with dots and commas, which, however, does not really address my problem because of the format of the input and the desired output. Thanks in advance for your help.