Regular Expressions
Explore how to use Python's regular expressions to create powerful pattern-matching rules. Learn about regex metacharacters and functions like re.search to validate input and manipulate strings effectively.
We'll cover the following...
The string methods find(), index(), and the membership operator in let us find out whether a string is a substring of another.
However, we often need a more sophisticated pattern-matching ability. This is facilitated through regular expressions (also called REs or regex).
Regular expressions are often used for validating input. For example, when we fill out a form online, the name, age, email address, mobile number, etc., are matched against acceptable patterns. The input is considered valid if the values we enter match these patterns.
For example, a mobile number is considered invalid if its length is ...