Check Password

I am trying to create a RegEx pattern to check a string, but can’t figure out how to get mine to work. I want it to be at least 8 characters and have a single uppercase, a single special character (!@#), and the rest lowercase or numbers. My single, I mean one, not at least one.

Here is what I have so far (this doesn’t seem to work) -


^(?=.*[!@#])(?=.*[A-Z])[a-z0-9]{8,}$

If I try the following, it works, but I think the period means that the remaining 6+ characters can be pretty much any character except for newline -


^(?=.*[!@#])(?=.*[A-Z]).{8,}$

This pattern is not maintainable. I think that you should do it without regex. You can parse the password and count the totals of upper, lower, special and other chars.