I would like to write a regular expression in Python that checks if a string does not contain more than 2 same letters in a row, e.g. wood valid, woood not valid
I tried it with
[a-zA-z]{,2}
but that does not work
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.
The easiest way of doing this would be using a backreference twice:
This checks for the opposite of what you’re asking for, so negate the result. If you’re using this as a part of a larger regex, remember to change the backreference index if needed.