I am trying to parse passwd and group files for login names, so this brought me to think about what characters are valid, which I never thought about before and always assumed it's /[a-z]+/.

Here is the explanation from the manpages of useradd and groupadd:
Usernames must start with a lower case letter or an underscore, followed by lower case letters, digits,
underscores, or dashes. They can end with a dollar sign. In regular expression terms: [a-z_][a-z0-9_-]*[$]?

Usernames may only be up to 32 characters long.

Groupnames must start with a lower case letter or an underscore, followed by lower case letters, digits,
underscores, or dashes. They can end with a dollar sign. In regular expression terms: [a-z_][a-z0-9_-]*[$]?

They even provide ready-to-go regular expressions for matching, but does anyone know about the ending dollar sign?

I am guessing it must be some sort of history, but I am not that old to know about it and I have never seen any login username contains dollar sign in any OS I have ever used.

I tried to find an answer on Internet, but didn't see any page talked about this (why would one?). However, there are some results about Windows login with ending dollar sign.