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 OverflowRegex101
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.
Regex Quiz
Learn regex and challenge yourself in a unique regex quiz: play progressively harder levels and compete with others in creating the shortest solutions.
Community Patterns
You have to replace each ... ` This example code must return : [Put here the regex to replace \k with \k]Submitted by nitrateag ... This regex matches only when all the following are true: password must contain 1 number (0-9) password must contain 1 uppercase letters password must contain 1 lowercase letters password must contain 1 non-alpha numeric number password is 8-16 characters with no spaceSubmitted by qho ... Validates a RFC3339 ...
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.
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
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
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
rexi: A Terminal UI for Regex Testing Built in Python
Terminal version of regex101 yes please More on reddit.com
Videos
04:28
How to Validate Email using regex in Python - YouTube
18:58
Regular Expressions in Python - YouTube
03:15
Python validate email address using RegEx - YouTube
03:32
#11 Python Validate Mobile Number using RegEx - YouTube
05:16
#10 Python Validate Password using RegEx - YouTube
Top answer 1 of 4
5
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
2 of 4
2
user_name = '1' #something that doesn't validate
while not re.match("^[A-Za-z]*$", user_name):
user_name = input("Please enter your name: ")
print ("Error! Make sure you only use letters in your name")
else:
print("Hello! "+ user_name)
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.
Top answer 1 of 2
108
Similar to Java. Use re.error exception:
import re
try:
re.compile('[')
is_valid = True
except re.error:
is_valid = False
exception
re.errorException raised when a string passed to one of the functions here 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.
2 of 2
6
Another fancy way to write the same answer:
import re
try:
print(bool(re.compile(input())))
except re.error:
print('False')
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.
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:
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.
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.
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.
Top answer 1 of 10
728
import re
pattern = re.compile("^([A-Z][0-9]+)+$")
pattern.match(string)
2 of 10
407
One-liner: re.match(r"pattern", string) # No need to compile
import re
>>> if re.match(r"hello[0-9]+", 'hello1'):
... print('Yes')
...
Yes
You can evaluate it as bool if needed
>>> bool(re.match(r"hello[0-9]+", 'hello1'))
True
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.