Converting a 10 digit phone number to US format using Regex in Python
Text preprocessing is one of the most important tasks in Natural Language Processing. You may want to extract number from a string. Writing a manual script for such processing task requires a lot of effort and at most times it is prone to errors. Keeping in view the importance of these preprocessing tasks, the concept of Regular Expression have been developed in different programming languages in order to ease these text processing tasks.
To implement Regular Expression, the python re package can be used and to be used it can be easily imported like any other inbuilt python module.
Steps for converting a 10-digit phone number to its corresponding US number format:
- Import the python re package.
- Write a function that takes the phone number to be formatted as argument and processes it.
- Now simply call the function and pass the value.
Call geek (321) 963-0612
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course