...

/

Regular Expressions

Regular Expressions

Learn about regular expressions and their functionality in Python.

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 ...