Hello iam trying to find all the degits in a string but it returns an empty list
my code :
import re
re.findall(r'/d','5585858')
>>>> []
what is the error please ?
Hello iam trying to find all the degits in a string but it returns an empty list
my code :
import re
re.findall(r'/d','5585858')
>>>> []
what is the error please ?
You have a wrong pattern, you need \d
first and for get all of digits you can add +
to \d
for match 1 or more combine of digits :
re.findall(r'\d+','5585858')
Also based on your string you can use other functions like re.search
that may be more efficient.
And if you want to convert your string to list you can simply use list
:
>>> list('5585858')
['5', '5', '8', '5', '8', '5', '8']
use '\d+'
instead of '/d'
>>> import re
>>> re.findall(r'\d+', '5585858')
['5585858']
You don't even need a regular expression for that.
>>> [number for number in '5585a858' if number.isdigit()]
['5', '5', '8', '5', '8', '5', '8']