In this article, we will learn about how to use Python Regex to validate name using IGNORECASE.
re.IGNORECASE : This flag allows for case-insensitive matching of the Regular Expression with the given string i.e. expressions like
[A-Z] will match lowercase letters, too. Generally, It’s passed as an optional argument to
Let’s consider an example of a form where the user is asked to enter their name and we have to validate it using RegEx. The format for entering name is as follow:
- Mr. or Mrs. or Ms. (Either one) followed by a single space
- First Name, followed by a single space
- Middle Name(optional), followed by a single space
- Last Name(optional)
Input : Mr. Albus Severus Potter Output : Valid Input : Lily and Mr. Harry Potter Output : Invalid
Note : Since, we are using IGNORECASE flag, the first character of First, Second, and Last name may or may not be capital.
Below is the Python code –
Valid Invalid Valid valid
- Password validation in Python
- Verbose in Python Regex
- Python | Form validation using django
- Pattern matching in Python with Regex
- Python Regex: re.search() VS re.findall()
- Python | Parse a website with regex and urllib
- Find all the patterns of “1(0+)1” in a given string using Python Regex
- The most occurring number in a string using Regex in python
- Python | Program that matches a word containing 'g' followed by one or more e's using regex
- Python | Check if string matches regex list
- Python Regex to extract maximum numeric value from a string
- Python | Swap Name and Date using Group Capturing in Regex
- Python Regex - Program to accept string starting with vowel
- Python regex | Check whether the input is Floating point number or not
- Regex in Python to put spaces between words starting with capital letters
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.