Regular Expressions 101

Community Patterns

Community Library Entry

2

Regular Expression
PCRE (PHP <7.3)

/
(?=^.{8,32}$)(?=.*\d)(?=.*[!@#$%^&*]+)(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$
/

Description

This RegEx was posted on a Ruby site as one for enforcing password pattern. I added {8,32} to limit the length of the password, even though I realize no one has passwords longer than that. Rules: at least 1 digit, 1 special character (as defined), 1 upper case and 1 lower case character, between 8 and 32 characters total.

The question I have pertains to the trailing .*$ pattern. On the Rubular site, this is required. On regex101.com it does not see to add value to the regex.

Do I need the .*$ on the expression?

Submitted by Dave Phillips - 10 years ago