Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to extract all the numbers from a string in Python

3 Answers

0 votes
import re

string = "a3 145 python 3.14 java x6 50 3 c#"

r = re.findall(r'\b\d+\b', string)

for number in r:
    print(number)


'''
run:

145
3
14
50
3

'''

 





answered Dec 26, 2017 by avibootz
0 votes
import re

string = "a3 145 python 3.14 java x6 50 3 c#"

r = re.findall(r'\b\d+\b', string)

print(r)


'''
run:

['145', '3', '14', '50', '3']

'''

 





answered Dec 26, 2017 by avibootz
0 votes
import re

string = "a3 145 python 3.14 java x6 50 7 c#"

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

print(r)


'''
run:

['3', '145', '3', '14', '6', '50', '7']

'''

 





answered Dec 26, 2017 by avibootz

Related questions

1 answer 70 views
3 answers 134 views
1 answer 71 views
2 answers 68 views
...