How to get all the 3 digit numbers from a string in Python

2 Answers

0 votes
import re

s = "jdh 123 32 sd 987 gsha 1 3 788"

print(re.findall(r"\b\d{3}\b", s))




'''
run:

['123', '987', '788']

'''

 



answered Jul 18, 2019 by avibootz
0 votes
import re

s = "php 123 32 c++ 987 python 1 3 788 9999 999"


lst = re.findall(r"\b\d{3}\b", s)

print(lst)




'''
run:

['123', '987', '788', '999']

'''

 



answered Jul 18, 2019 by avibootz
...