The regular expression in Python is a search pattern formed by a sequence of characters.
The sub() method is used to replace all occurrences of a pattern in the string with a substring/character. There is an upper limit to replacing characters.
The method returns a string that contains characters after replacing the character. The method is included in the re library.
Syntax:
regular.sub(regularExp, replaceChar, string, UL)
Let's take an example to understand the problem,
Input:
string = "Your mobile number is : 9988-214-631"
Output:
9988214631
Program to illustrate the working of our solution
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer