Python has an inbuilt re module which allows us to solve the various problems based on pattern matching and string manipulation. The re module or regex is an abbreviated form of the regular expression. This module of Python in our daily life is very useful, by using re module you can find the contact number, email-id, special pattern, etc from a file or given sentences. The re module provides a lot of metacharacters and to solve the problem we will use the \d which is used to match any decimal digits(0-9) in the given string or sentence.
Let's take an example to understand the problem better,
Input:
"Hello! I am bipin Kumar and my contact number is 918481234422.
May i know the call logs of my number"
Output:
918481234422
Explanation:
The program will have to find a substring that contains
12 digit substring and print it.
Algorithm to solve the above problem
- Initially, we will import the re module in the program.
- Assign the given string or sentence in a variable.
- As we all know the contact number or mobile will be of 12 digits that why we will form a format that will use to extract the mobile number.
- Now, print the extracted number.
Program:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer