It will most likely be easier to code the logic. A regular expression is used to match patterns. Passwords tend to be somewhat random strings, so the problem cannot be easily solved by regex. It is possible, but it will be mysteriously read and difficult to maintain.
source share