[Solved] Find all numbers in a string in Python 3 [duplicate]


Using the regular expressions as suggested by AChampion, you can do the following.

string = "44-23+44*4522"
import re
result = re.findall(r'\d+',string)

The r” signifies raw text, the ‘\d’ find a decimal character and the + signifies 1 or more occurrences. If you expect floating points in your string that you don’t want to be separated, you might what to bracket with a period ‘.’.

re.findall(r'[\d\.]+',string)

1

solved Find all numbers in a string in Python 3 [duplicate]