Name validation using IGNORECASE in Python Regex Last Updated : 29 Dec, 2020 Comments Improve Suggest changes Like Article Like Report 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 re.compile(). 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) Examples: 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 - Python3 # Python program to validate name using IGNORECASE in RegEx # Importing re package import re def validating_name(name): # RegexObject = re.compile( Regular expression, flag ) # Compiles a regular expression pattern into a regular expression object regex_name = re.compile(r'^(Mr\.|Mrs\.|Ms\.) ([a-z]+)( [a-z]+)*( [a-z]+)*$', re.IGNORECASE) # RegexObject is matched with the desired # string using search function # In case a match is found, search() returns # MatchObject Instance # If match is not found, it return None res = regex_name.search(name) # If match is found, the string is valid if res: print("Valid") # If match is not found, string is invalid else: print("Invalid") # Driver Code validating_name('Mr. Albus Severus Potter') validating_name('Lily and Mr. Harry Potter') validating_name('Mr. Cedric') validating_name('Mr. sirius black') Output: Valid Invalid Valid valid Comment More infoAdvertise with us Next Article Name validation using IGNORECASE in Python Regex P PoojaRani24 Follow Improve Article Tags : Python python-regex Python Regex-programs Practice Tags : python Similar Reads How to check a valid regex string using Python? A Regex (Regular Expression) is a sequence of characters used for defining a pattern. This pattern could be used for searching, replacing and other operations. Regex is extensively utilized in applications that require input validation, Password validation, Pattern Recognition, search and replace ut 6 min read Convert string to title case in Python In this article, we will see how to convert the string to a title case in Python. The str.title() method capitalizes the first letter of every word.Pythons = "geeks for geeks" result = s.title() print(result) OutputGeeks For Geeks Explanation:The s.title() method converts the string "python is fun" 2 min read Parsing and Processing URL using Python - Regex Prerequisite: Regular Expression in Python URL or Uniform Resource Locator consists of many information parts, such as the domain name, path, port number etc. Any URL can be processed and parsed using Regular Expression. So for using Regular Expression we have to use re library in Python. Example: U 3 min read Python | Selective casing in String Sometimes, while working with Python, we can have a problem in which we need to perform the case change of certain characters in string. This kind of problem can come in many types of applications. Let's discuss certain ways in which this problem can be solved. Method #1 : Using enumerate() + loop + 6 min read How to remove text inside brackets in Python? In this article, we will learn how to remove content inside brackets without removing brackets in python. Examples: Input: (hai)geeks Output: ()geeks Input: (geeks)for(geeks) Output: ()for() We can remove content inside brackets without removing brackets in 2 methods, one of them is to use the inbui 4 min read Like