Using a while True loop only break out with break if you got a right answer:

while True:
    user_name = input("Please enter your name: ")
    if not re.match("^[A-Za-z]*$", user_name):
        print ("Error! Make sure you only use letters in your name")
    else:
        print("Hello "+ user_name)
        break
Answer from Mike Müller on Stack Overflow
🌐
Pythex
pythex.org
Pythex: a Python regular expression editor
Pythex is a real-time regular expression editor for Python, a quick way to test your regular expressions.
🌐
W3Schools
w3schools.com › python › python_regex.asp
Python RegEx
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... A RegEx, or Regular Expression, is a sequence of characters that forms a search pattern.
Discussions

python - Validate user input using regular expressions - Stack Overflow
I would like to be able to validate that the user has entered a valid name within my program. If they have not entered a valid name i want the program to continue to prompt them to enter their name More on stackoverflow.com
🌐 stackoverflow.com
How to check if a string is a valid regex in Python? - Stack Overflow
Exception raised when a string ... is not a valid regular expression (for example, it might contain unmatched parentheses) or when some other error occurs during compilation or matching. It is never an error if a string contains no match for a pattern. ... Sign up to request clarification or add additional context in comments. ... @alvas, As long as you're using Regular expression supported by Python. 2013-10-28T09:27:48.093Z+00:00 ... This is OK for regex syntax errors, ... More on stackoverflow.com
🌐 stackoverflow.com
python regex for password validation - Stack Overflow
I have the following requirement to validate the password with below context at least one digit at least one uppercase letter at least one lowercase letter at least one special character[$@#] Below More on stackoverflow.com
🌐 stackoverflow.com
October 5, 2017
python - Check if string matches pattern - Stack Overflow
How do I check if a string matches the following pattern? Uppercase letter, number(s), uppercase letter, number(s)... Example: These would match: A1B2 B10L1 C1N200J1 These wouldn't ('^' points to More on stackoverflow.com
🌐 stackoverflow.com
🌐
Regex101
regex101.com
regex101: build, test, and debug regex
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-check-a-valid-regex-string-using-python
How to check a valid regex string using Python? - GeeksforGeeks
July 31, 2023 - In the following code, we would be specifying re.error as the exception in the except clause of the try-except block. This error is encountered when an invalid regex pattern is found, during the compilation of the pattern.
🌐
Python documentation
docs.python.org › 3 › howto › regex.html
Regular Expression HOWTO — Python 3.14.3 documentation
Let’s take an example: \w matches any alphanumeric character. If the regex pattern is expressed in bytes, this is equivalent to the class [a-zA-Z0-9_]. If the regex pattern is a string, \w will match all the characters marked as letters in ...
Find elsewhere
🌐
Great Learning
mygreatlearning.com › blog › it/software development › introduction to regular expression in python | regex in python
Introduction to Regular Expression in Python | Regex in Python
November 18, 2024 - The domain name [for example com, org, net, in, us, info] part contains letters, digits, hyphens, and dots. Finally here is the program that can validate email ids using Regular Expressions
🌐
Medium
rlrocha.medium.com › validation-mask-through-regex-with-python-4b03993ad1ab
Validation mask through Regex with Python | by Rafael Rocha | Medium
November 16, 2021 - The function match of re python library is used to test the regex of each field. The first argument of function match is the regex created, and the second is the string to be tested. Bellow is showed the application of re. import reregex = “^[a-z]+@[a-z]+.br$' string = “whoisgamora@.br'if bool(re.match(regex, string)): print(‘Valid email!’)else: print(‘Invalid email!’) This example generates the message Invalid email!, because there isn’t any symbol of Σ between @ and .br.
🌐
QA Touch
qatouch.com › home › python regex testing: a comprehensive guide with examples
Python Regex Testing: A Comprehensive Guide with Examples
June 24, 2025 - Here’s how you can achieve this using Python regex: In this example, the phone_pattern regex is designed to match phone numbers in two formats: ###-###-#### and ##########, where # represents a digit.
🌐
ExtendsClass
extendsclass.com › regex-tester.html
Online Regex tester and visualizer - Python, PHP, Ruby, JavaScript, Java, MySQL
CyrilEx is an online regex debugger, it allows you to test regular expression in PHP (PCRE), Python, Ruby, JavaScript, Java and MySQL. It helps you to test and debug regex online, you can visualize the matches when matching a string against a regex. A regex visualizer allows to visualize your regex, it helps to understand it. This feature is useful for large regexes. Cyrilex also allows you to generate a string example from a RegEx.
🌐
ACCELQ
accelq.com › home › master python regex testing: your go-to guide for test automation
Your Go-To Guide to Python Regex Testing for Automation
November 6, 2025 - The first step is importing Python’s re module. It’s the built-in module that lets you work with regex. ... A regex pattern is a string that defines the search behavior you want. You’ll need to create a pattern that matches the data you’re looking for. For example, here’s a regex pattern that matches a Social Security Number (SSN) in the format XXX-XX-XXXX:
🌐
Python-Fiddle
python-fiddle.com › tools › regex
Online Python Regex Playground
In the example below, we use a lookbehind to match digits that are preceded by a dollar sign ($), but without including the dollar sign in the result.
🌐
Anaconda
anaconda.com › home › blog › advanced data validation using regular expressions with python in excel
Advanced Data Validation using Regular Expressions with Python in Excel | Anaconda
August 8, 2025 - For this reason, in this post, we will consider the regex syntax as supported by the re Python package included with Python in Excel. The regular expression syntax, and its corresponding list of symbols, is notoriously difficult for beginners, and sometimes cumbersome to remember even for expert users. But don’t worry; we will explain in detail every step in creating the regular expressions when working on our advanced data validation filters.
🌐
Qodex
qodex.ai › home › all tools › getting started › javascript regex tester
Python Regex Tester Online | Validate, Test ...
Whether you’re working on email validation, password security, or URL parsing, this tool helps you validate patterns instantly with visual feedback. It supports all standard JavaScript regex syntax and flags. Need sample data? Use our Email Generator, Password Generator, or UUID Generator to test your expressions thoroughly. For testing patterns in other languages, explore our Java Regex Tester, Python Regex Tester, or Go Regex Tester.
Rating: 4.9 ​ - ​ 60 votes
🌐
Mimo
mimo.org › glossary › python › regex-regular-expressions
Python Regex: Master Regular Expressions in Python
This example validates an email address and a phone number to ensure they meet the correct format. Regex in Python code is similar to regex in other languages like JavaScript, Perl, and Java.
🌐
Stack Abuse
stackabuse.com › python-validate-email-address-with-regular-expressions-regex
Python: Validate Email Address with Regular Expressions (RegEx)
March 28, 2023 - In this guide, we'll take a look at how to validate email addresses in Python with Regular Expressions, with a general-purpose simple expression as well as an RFC5322-compliant robust regex.
🌐
Educative
educative.io › answers › how-to-do-password-validation-in-python-using-regex
How to do password validation in Python using regex
In Python, we can use the re library for all regex operations. Line 1: We import the re module. Line 2: We define a function named validate_password that takes a string.