Home >>Python Programs >Python Extract numbers from string
In this example, we will see a Python program through which we can extract the mobile number from the given string.
In this program, we will use the re module. A string will be given as input to the program and it will extract the mobile number from it.
Algo:
# importing the module
import re
# string
string='''Hello Everyone!! My name is Jerry and i am a Developer. You can contact me on 9876543210. Also you can write me a mail.'''
# extracting the mobile number
Phonenumber=re.compile(r'\d\d\d\d\d\d\d\d\d\d')
m=Phonenumber.search(string)
# printing the result
print('mobile number found from the string : ',m.group())