Regex to test for lowercase characters

Regular expressions. So powerful, but so tricky to learn!
Recently I found myself scratching my head over how to write a regular expression to check that a string contained only lowercase characters.
I used so many different combinations of[a-z], ^\W, [0–9], [a-z]^\W and more. No dice. I couldn’t figure out the correct combination. Finally I thought: oh, so simple, I’ll just do the inverse! So I did the following:
const isLowercaseOnly = (string) => {
const nonLowercaseLetters = /[^a-z]/g;
return !nonLowercaseLetters.test(string);
};This works, but now I have to deal with inverse. A bit confusing.
Luckily, I was working with a great mentor from Exercism who helped me out with the expression. It is ^[a-z]+$. To explain:
^: start the string with something from[a-z]+: there can be one or more occurrences from the range[a-z]. Without this, the regex would only be true for strings with only one lowercase character present. e.g.‘h’would betrue, but‘hello’would befalse.$: the string must end with something from[a-z]- As the expression only contains one range between the
^and$, no other characters are permitted. So you don’t need to worry about digits, white spaces, uppercase etc. creeping in because the expression has to start and end with[a-z].
So my final function is:
const isLowercaseOnly = (string) => {
const lowercaseOnly = /^[a-z]+$/g;
return lowercaseOnly.test(string);
}Ta-dah! No more negatives. I also found this website to be incredibly powerful to test regex combinations. Thank you to whomever created it!