re.IGNORECASE : This flag allows you to match a regular expression to a given string without
re.IGNORECASE case, that is, expressions such as
[AZ] will also match lowercase letters. Typically, it is passed as an optional argument to
re.compile () .
Let’s see an example of a form that asks the user to enter his name and we have to validate it with RegEx. The format for entering the name is as follows:
- Mister or Mrs. or Miss (Or one) followed by a space
- First name followed by one space
- Middle name (optional) followed by one space
- Last name (optional)
Input : Mr. Albus Severus Potter Output : Valid Input : Lily and Mr. Harry Potter Output : Invalid
Note. Since we are using the IGNORECASE flag, the first character of the first name, first name and last name may or may not be capitalized.
Below is the Python code —
Valid Invalid Valid valid