One of the HTML input fields in an app I’m working on is being validated with the following regex pattern:
.{5,}+
What is this checking for?
Other fields are being checked with this pattern which I also don’t understand:
.+
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.
We can break your pattern down into three parts:
The dot is a wildcard, it matches any character (except for newlines, by default, unless the
/smodifier is set).{5,}is specifies repetition on the dot. It says that the dot must match at least 5 times. If there was a number after the comma, the dot would have to match between 5 and that number of times, but since there’s no number, it can match infinite times.In your first pattern, the
+is a possessive quantifier (see below for how+can mean different things in different situations). It tells the regular expression engine that once it’s satisfied the previous condition (ie..{5,}), it should not try to backtrack.Your second pattern is simpler. The dot still means the same thing as above (works as a wildcard). However, here the
+has a different meaning, and is a repetition operator, meaning that the dot must match 1 or more times (that could also be expressed as.{1,}, as we saw above).As you can see,
+has a different meaning depending on context. When used on its own, it is a repetition operator. However when it follows a different repetition operator (either*,?,+or{...}) it becomes a possessive quantifier.