How to extract only numbers from input file. Numbers can be float/int

后端 未结 3 669
清歌不尽
清歌不尽 2021-01-29 13:42

I want to extract numbers(integers and float) from a file(exclude all special symbols and alphabets). Numbers from all positions.

import re
file = open(\'input_f         


        
3条回答
  •  滥情空心
    2021-01-29 14:26

    Without clarification, you can try the following.

    re.findall(r'[+-]?\d+(?:\.\d+)?', line)
    

提交回复
热议问题