Does there exist a regular expression that matches no strings? If so, what is it?
To be precise, I’m looking for a regular expression r such that the following Python code outputs True for any string s:
import re
print(re.match(r, s) is None)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If your regex engine supports lookahead (which Python’s does):
Otherwise something like this would work too:
A word break can’t occur by itself!
Or,
The end of the string can’t match at the start of the string unless the string is empty, and we prevent it from being empty by requiring that we match at least one character.
Then again,
^/$/\bare really just lookarounds in disguise.